How to create a ByteBuffer in Java

in java •  7 years ago  (edited)

There are many ways to create a ByteBuffer:

  • Create a ByteBuffer using an existing array
byte[] bytes = new byte[BUFFER_SIZE];
ByteBuffer buffer = ByteBuffer.wrap(bytes);

  • Create a non-direct ByteBuffer with a specific byte capacity
ByteBuffer buffer = ByteBuffer.allocate(10);

  • Create a direct ByteBuffer with a specific byte capacity
ByteBuffer buffer = ByteBuffer.allocateDirect(10);

Please upvote, if you find it useful.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

@resteemator is a new bot casting votes for its followers. Follow @resteemator and vote this comment to increase your chance to be voted in the future!

This post received a 0.015 SBD (0.45%) upvote from @upvotewhale thanks to @mirahu! For more information, check out my profile!

This post has received a 0.09 % upvote from @drotto thanks to: @mirahu.