DoubleBuffer order() methods in Java with Examples

The java.nio.DoubleBuffer has order() function.The ByteOrder of this DoubleBuffer instance can be obtained using the DoubleBuffer class.

Syntax:

Return Value: This function gives back the byte order of this buffer.

Example 1:

The code shows how to manage and examine the contents and byte order of a buffer using Java's DoubleBuffer. Four double values are created and added to a DoubleBuffer with a capacity of 4. Rewind() is used to reset the buffer's position to 0, and the order() method is used to determine the buffer's byte order. After that, the contents of the buffer and its byte order are created. By default, DoubleBuffer uses the system's native byte order, which is displayed along with the buffer's contents.

Implementation:

FileName: BufferOrderexample1.java

Output:

 
The DoubleBuffer is given by : [10.5, 20.5, 30.5, 40.5]
The Order is given by : LITTLE_ENDIAN   

Example 2:

The code illustrates how to examine the buffer's byte order using DoubleBuffer. Since no values are added, a DoubleBuffer with a capacity of 4 is generated but remains empty. Using rewind(), the buffer's position is reset to 0, and the system's native byte order is obtained by calling the order() method. An array of zeros will be produced by Arrays.toString(db.array()) as no data is added to the buffer.

Implementation:

FileName: BufferOrderexample2.java

Output:

 
The DoubleBuffer is given by : [0.0, 0.0, 0.0, 0.0]
The Order is given by : LITTLE_ENDIAN