Java DoubleBuffer order()方法及示例

来源:这里教程网 时间:2026-02-17 20:48:59 作者:

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-

相关推荐