Sorry, you canโt. What you are asking for is essentially C / C ++ pointer arithmetic, and there is no such thing in Java.
However, if you want to use a different interface, you might be in luck with the Commons Primitives ArrayByteList . This is not a simple List<Byte> because it is supported by a true byte array - therefore, the memory overhead due to the use of byte objects. You will still have some overhead object, but this is acceptable in practical cases.
Most importantly, it supports slices using the ArrayByteList.subList() method, which does not create a copy. You can check the source code , the slice is implemented as a reference to the source array plus two markers for the start and end positions.
However, keep in mind that avoiding copying means that changes to the slice are reflected in the original array. This is probably what you want, but be very careful anyway - especially if you are not coming from a C / C ++ background where these things are common practice.
source share