Java ByteBuffer get byte order:Big Endian or Little Endian

Description

Java ByteBuffer get byte order:Big Endian or Little Endian

import java.nio.ByteBuffer;

public class Main {
  public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(2);
    System.out.println("Default Byte Order: " + bb.order());
    bb.putShort((short) 67);
    bb.flip();//  w  w w  . j  a v a 2 s .  c o  m

    System.out.println("Byte Order: " + bb.order());
    while (bb.hasRemaining()) {
      System.out.print(bb.get() + "  ");
    }
  }
}



PreviousNext

Related