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

前端 未结 9 1816
执念已碎
执念已碎 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条回答
  • 2020-12-28 12:42

    Many classes in Java accept a subset of an arrays as parameter. E.g. Writer.write(char cbuf[], int off, int len). Maybe this already suffices for your usecase.

    0 讨论(0)
  • 2020-12-28 12:43

    You could use (ArrayList).subList(value1, value2) i belive, perhaps that could help in your case? That is ofcourse if you want to use an ArrayList.

    0 讨论(0)
  • 2020-12-28 12:45
    Arrays.asList(array).subList(x, y).
    

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

    0 讨论(0)
提交回复
热议问题