The Java API documentation for ByteBuffer.arrayOffset states:
Returns the offset within this buffer's backing array of the first element of the buffer (optional operation).
I cannot figure out how to get arrayOffset()
to return a non-zero value. Does anyone know how to change the result of a call to the ByteBuffer.arrayOffset()
method?
Updated to describe the use of slice on array backed ByteBuffer.
The array offset points to an offset in a backing buffer. One of the ways to get a value other than 0 is to create an array backed ByteBuffer, then call slice. The result of slice will have an offset value corresponding to the current position of the original ByteBuffer. The array offset is only useful when getting the backing array to interact with directly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With