Java中的IntBuffer arrayOffset()方法
使用arrayOffset()
类java.nio.IntBuffer中的方法获得缓冲区数组内部缓冲区的第一个元素的偏移量。如果数组支持的缓冲区是只读的,则抛出ReadOnlyBufferException。
演示此的程序如下所示-
示例
import java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(5); buffer.put(8); buffer.put(1); buffer.put(3); buffer.put(7); buffer.put(5); buffer.rewind(); System.out.println("The IntBuffer is: " + Arrays.toString(buffer.array())); System.out.println("The arrayOffset is: " + buffer.arrayOffset()); } catch (IllegalArgumentException e) { System.out.println("Error!!! IllegalArgumentException"); } catch (ReadOnlyBufferException e) { System.out.println("Error!!! ReadOnlyBufferException"); } } }
上面程序的输出如下-
输出结果
The IntBuffer is: [8, 1, 3, 7, 5] The arrayOffset is: 0