ByteBuffer
suggest changeIntroduction
The ByteBuffer class was introduced in Java 1.4 to make binary data easier to handle. It is especially suited to primitive values. It lets you create a buffer and then read and write that data without manipulating a byte[] directly.
Syntax
- 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’);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents