Java.lang.Character.reverseBytes() Method
Advertisements
Description
The java.lang.Character.reverseBytes(char ch) returns the value obtained by reversing the order of the bytes in the specified char value.
Declaration
Following is the declaration for java.lang.Character.reverseBytes() method
public static char reverseBytes(char ch)
Parameters
NA
Return Value
This method returns the value obtained by reversing (or, equivalently, swapping) the bytes in the specified char value.
Exception
NA
Example
The following example shows the usage of lang.Character.reverseBytes() method.
package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
// create 2 char primitives ch1, ch2
char ch1, ch2;
// assign value to ch1
ch1 = '\u4d00';
// assign result of reverseBytes on ch1 to ch2
ch2 = Character.reverseBytes(ch1);
String str = "Reversing bytes on ch1 gives " + ch2;
// print ch2 value
System.out.println( str );
}
}
Let us compile and run the above program, this will produce the following result:
Reversing bytes on ch1 gives M