Java ByteBuffer create from byte array

Description

Java ByteBuffer create from byte array

import java.nio.ByteBuffer;

public class Main {
  public static void main(String[] args) {
    // Have an array of bytes
    byte[] byteArray = new byte[512];

    // Create a byte buffer by wrapping the byteArray
    ByteBuffer bb = ByteBuffer.wrap(byteArray);
    System.out.println("Capacity: " + bb.capacity());
    System.out.println("Limit: " + bb.limit());
    System.out.println("Position: " + bb.position());

  }/* ww  w.  j av  a  2 s  .c o  m*/
}



PreviousNext

Related