IntBuffer 是一个 Java NIO 类,用于包装一个 int 类型的数组或一个 int 缓冲区。它提供了一些方法来方便地读取和写入 int 值。 IntBuffer 的创建方式有两种: 1. 通过 allocate() 方法创建一个指定容量的 IntBuffer 对象。 ```java IntBuffer buffer = IntBuffer.allocate(10); ``` 2. 通过 wrap() 方法创建一个已有 int 数组或 int 缓冲区的 IntBuffer 对象。 ```java int[] array = new int[10]; IntBuffer buffer = IntBuffer.wrap(array); ``` IntBuffer 对象提供了一些方法来读取和写入 int 值,例如: ```java // 写入 int 值 buffer.put(1); buffer.put(2); buffer.put(3); // 读取 int 值 buffer.flip(); // 切换为读模式 int a = buffer.get(); int b = buffer.get(); int c = buffer.get(); ``` IntBuffer 还提供了一些其他的方法,例如 clear()、compact()、slice() 等,可以根据需要使用。