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


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


java.nio.CharBuffer类的order()方法用于检索此缓冲区的字节顺序。通过分配或包装现有char数组创建的char缓冲区的字节顺序是基础硬件的本机顺序。创建为字节缓冲区视图的char缓冲区的字节顺序是创建视图时字节缓冲区的字节顺序。

用法:

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 CharBuffer 
        // and allocating size capacity 
        CharBuffer cb 
            = CharBuffer.allocate(4); 
  
        // append the int value in the charbuffer 
        cb.append('a') 
            .append('b') 
            .append('c') 
            .append('d'); 
  
        // rewind the Bytebuffer 
        cb.rewind(); 
  
        // Retrive the ByteOrder 
        // using order() method 
        ByteOrder order = cb.order(); 
  
        // print the char buffer and order 
        System.out.println("CharBuffer is:"
                           + Arrays.toString(cb.array()) 
                           + "\nOrder:" + order); 
    } 
}
输出:
CharBuffer is:[a, b, c, d]
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 CharBuffer 
        // and allocating size capacity 
        CharBuffer cb = CharBuffer.allocate(4); 
  
        // Retrive the ByteOrder 
        // using order() method 
        ByteOrder order = cb.order(); 
  
        // print the char buffer and order 
        System.out.println("CharBuffer is:"
                           + Arrays.toString(cb.array()) 
                           + "\nOrder:" + order); 
    } 
}
输出:
CharBuffer is:[,,,  ]
Order:LITTLE_ENDIAN

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



相关用法


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