| 8 | public class IntBufferDemo { |
| 9 | private static final int BSIZE = 1024; |
| 10 | public static void main(String[] args) { |
| 11 | ByteBuffer bb = ByteBuffer.allocate(BSIZE); |
| 12 | IntBuffer ib = bb.asIntBuffer(); |
| 13 | // Store an array of int: |
| 14 | ib.put(new int[]{ 11, 42, 47, 99, 143, 811, 1016 }); |
| 15 | // Absolute location read and write: |
| 16 | System.out.println(ib.get(3)); |
| 17 | ib.put(3, 1811); |
| 18 | // Setting a new limit before rewinding the buffer. |
| 19 | ib.flip(); |
| 20 | while(ib.hasRemaining()) { |
| 21 | int i = ib.get(); |
| 22 | System.out.println(i); |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | /* Output: |
| 27 | 99 |