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

前端 未结 9 1885
执念已碎
执念已碎 2020-12-28 11:58

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

9条回答
  •  萌比男神i
    2020-12-28 12:41

    There is no way to declare a subarray in Java if you use built in arrays like byte[]. The reason is: The length of the array is stored with the data, not with the declaration of the reference to it. Hence a subarray which does not copy the data has no place where it can store the length! So for basic types you can use the mentioned efficient byte array copies and for higher types (List) there are methods available.

提交回复
热议问题