CharBuffer order() methods in Java with Examples
The order() method of java.nio.CharBuffer class is used to retrieve this buffer’s byte order. The byte order of a char buffer created by allocation or by wrapping an existing char array is the native order of the underlying hardware. The byte order of a char buffer created as a view of a byte buffer is that of the byte buffer at the moment that the view is created.
Syntax:
public abstract ByteOrder order()
Return Value: This method returns this buffer’s byte order.
Below are the examples to illustrate the order() method:
Examples 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
Examples 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
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/CharBuffer.html#order–
Recommended Posts:
- CharBuffer read() methods in Java with Examples
- CharBuffer length() methods in Java with Examples
- CharBuffer limit() methods in Java with Examples
- CharBuffer flip() methods in Java with Examples
- CharBuffer rewind() methods in Java with Examples
- CharBuffer subSequence() methods in Java with Examples
- CharBuffer position() methods in Java with Examples
- CharBuffer reset() methods in Java with Examples
- CharBuffer clear() methods in Java with Examples
- CharBuffer append() methods in Java with Examples
- CharBuffer chars() methods in Java with Examples
- CharBuffer charAt() methods in Java with Examples
- CharBuffer mark() methods in Java with Examples
- CharBuffer put() methods in Java
- CharBuffer get() methods in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.