Java IntBuffer store int and int array
import java.nio.ByteBuffer; import java.nio.IntBuffer; public class Main { private static final int BSIZE = 16; public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); System.out.println("ByteBuffer size:"+bb.capacity()); IntBuffer ib = bb.asIntBuffer(); System.out.println("IntBuffer size:"+ib.capacity()); // Store an array of int ib.put(new int[] { 1, 2, 3 }); ib.put(3, 1234);//w w w. j a v a2 s. c om ib.rewind(); while (ib.hasRemaining()) { int i = ib.get(); if (i == 0) break; // Else we'll get the entire buffer System.out.println(i); } } }