DoubleBuffer order() methods in Java with Examples

The order() method of java.nio.DoubleBuffer class is used to get the ByteOrder of this DoubleBuffe instance.

Syntax:

public abstract ByteOrder order()

Return Value: This method returns this buffer’s byte order.



Below are the examples to illustrate the order() method:

Examples 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// order() method
  
import java.nio.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // creating object of DoubleBuffer
        // and allocating size capacity
        DoubleBuffer db
            = DoubleBuffer.allocate(4);
  
        // put the double value
        // in the Doublebuffer
        db.put(10.5)
            .put(20.5)
            .put(30.5)
            .put(40.5);
  
        // rewind the Doublebuffer
        db.rewind();
  
        // Retrive the ByteOrder
        // using order() method
        ByteOrder order = db.order();
  
        // print the double buffer and order
        System.out.println("DoubleBuffer is : "
                           + Arrays.toString(
                                 db.array())
                           + "\nOrder: "
                           + order);
    }
}

chevron_right


Output:

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

Examples 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// order() method
  
import java.nio.*;
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // creating object of DoubleBuffer
        // and allocating size capacity
        DoubleBuffer db
            = DoubleBuffer.allocate(4);
  
        // Retrive the ByteOrder
        // using order() method
        ByteOrder order = db.order();
  
        // print the double buffer and order
        System.out.println("DoubleBuffer is : "
                           + Arrays.toString(
                                 db.array())
                           + "\nOrder: "
                           + order);
    }
}

chevron_right


Output:

DoubleBuffer is : [0.0, 0.0, 0.0, 0.0]
Order: LITTLE_ENDIAN

Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/DoubleBuffer.html#order–



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.