Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a sub array of array in Java, without copying data?

I have some library of classes, working with my data, which is being read into buffer. Is it possible somehow to avoid copying arrays again and again, passing parts of data deeper and deeper into processing methods? Well, it sounds strange, but in my particular case, there's a special writer, which divides data into blocks and writes them individually into different locations, so it just performs System.arraycopy, gets what it needs and calls underlying writer, with that new sub array. And this happens many times. What is the best approach to refactor such code?

like image 509
Illarion Kovalchuk Avatar asked Aug 03 '10 10:08

Illarion Kovalchuk


1 Answers

Arrays.asList(array).subList(x, y). 

This method doesn't give you an array, but a List, which is far more flexible.

like image 66
Ricky Clarkson Avatar answered Oct 25 '22 17:10

Ricky Clarkson