当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java DoubleBuffer order()用法及代码示例


java.nio.DoubleBuffer类的order()方法用于获取此DoubleBuffe实例的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(); 
  
        // 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); 
    } 
}
输出:
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); 
  
        // 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); 
    } 
}
输出:
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-



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 DoubleBuffer order() methods in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。