order()
The
order() method of
java.nio.ByteBuffer class is used to retrieve this buffer's byte order. The byte order is used when reading or writing multibyte values, and when creating buffers that are views of this byte buffer. The order of a newly-created byte buffer is always BIG_ENDIAN.
Syntax:
public final ByteOrder order()
Return Value: This method returns this buffer's byte order.
Below are the examples to illustrate the order() method:
Examples 1:
Output:
Original ByteBuffer:
10 20 30
Byte Value: BIG_ENDIAN
Examples 2:
Output:
Byte Value: BIG_ENDIAN
order(ByteOrder bo)
The order(ByteOrder bo) method of ByteBuffer is used to modifie this buffer's byte order.
Syntax:
public final ByteBuffer order(ByteOrder bo)
Parameters: This method takes the new byte order, either BIG_ENDIAN or LITTLE_ENDIAN as a parameter.
Return Value: This method returns This buffer.
Below are the examples to illustrate the
order(ByteOrder bo) method:
Examples 1:
Output:
Old Byte Order: BIG_ENDIAN
New Byte Order: LITTLE_ENDIAN
Examples 2: