Java中的 DoubleBuffer order() 方法及示例
Java.nio.DoubleBuffer类的order()方法用于获取此 DoubleBuffer 实例的 ByteOrder。
句法:
public abstract ByteOrder order()
返回值:此方法返回此缓冲区的字节顺序。
以下是说明 order() 方法的示例:
示例 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);
}
}
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);
}
}
输出:
DoubleBuffer is : [10.5, 20.5, 30.5, 40.5]
Order: LITTLE_ENDIAN
示例 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);
}
}
输出:
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–