Java Language ByteBuffer

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


The ByteBuffer class was introduced in java 1.4 to ease working on binary data. It's especially suited to use with primitive type data. It allows the creation, but also subsequent manipulation of a byte[]s on a higher abstraction level


  • byte[] arr = new byte[1000];
  • ByteBuffer buffer = ByteBuffer.wrap(arr);
  • ByteBuffer buffer = ByteBuffer.allocate(1024);
  • ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
  • byte b = buffer.get();
  • byte b = buffer.get(10);
  • short s = buffer.getShort(10);
  • buffer.put((byte) 120);
  • buffer.putChar('a');

Got any Java Language Question?