|
How to create a ByteBuffer |
|
|
This Java tip demonstrates a method of creating a ByteBuffer. Fixed capacity
bufferes that hold byte values are known as ByteBuffer. There may be various
ways of creating a ByteBuffer.
// Create a ByteBuffer using a byte array
byte[] bytes = new byte[10];
ByteBuffer buffer = ByteBuffer.wrap(bytes);
// Create a non-direct ByteBuffer with a 10 byte capacity
// The underlying storage is a byte array.
buffer = ByteBuffer.allocate(10);
// Create a memory-mapped ByteBuffer with a 10 byte capacity.
buffer = ByteBuffer.allocateDirect(10);
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.