How to create a ByteBuffer in Java

in #java7 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.

Sort:  

@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.

Coin Marketplace

STEEM 0.26
TRX 0.30
JST 0.046
BTC 101550.10
ETH 3912.76
SBD 3.63