Java DoubleBuffer order()方法及示例

Java DoubleBuffer order()方法及示例

java.nio.DoubleBuffer 类的 order() 方法用于获取该DoubleBuffer实例的ByteOrder。

语法

public abstract ByteOrder order()

返回值: 该方法返回该缓冲区的字节顺序。
以下是说明order()方法的例子:
例子 1 :

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

输出

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

例子 2 :

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

输出

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

参考资料: https://docs.oracle.com/javase/9/docs/api/java/nio/DoubleBuffer.html#order-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程