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-
相關用法
- Java CharBuffer clear()用法及代碼示例
- Java CharBuffer limit()用法及代碼示例
- Java CharBuffer rewind()用法及代碼示例
- Java CharBuffer reset()用法及代碼示例
- Java CharBuffer subSequence()用法及代碼示例
- Java CharBuffer mark()用法及代碼示例
- Java CharBuffer position()用法及代碼示例
- Java CharBuffer charAt()用法及代碼示例
- Java CharBuffer chars()用法及代碼示例
- Java CharBuffer read()用法及代碼示例
- Java CharBuffer append()用法及代碼示例
- Java CharBuffer flip()用法及代碼示例
- Java CharBuffer length()用法及代碼示例
- Java CharBuffer get()用法及代碼示例
- Java CharBuffer put()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 CharBuffer order() methods in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。