Wednesday, July 3, 2024
HomeLanguagesJavaDoubleBuffer order() methods in Java with Examples

DoubleBuffer order() methods in Java with Examples

The order() method of java.nio.DoubleBuffer class is used to get the ByteOrder of this DoubleBuffer 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: 

Java




// 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();
 
        // Retrieve 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);
    }
}


Output: 

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

 

Examples 2: 

Java




// 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);
 
        // Retrieve 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);
    }
}


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–

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments