Java Character.reverseBytes() Method Last Updated : 14 May, 2025 Comments Improve Suggest changes Like Article Like Report The Character.reverseBytes() method in Java is a utility function from the java.lang.Character class. This method is used to reverse the order of the two bytes in a given 16-bit Unicode character (char). All Java characters are two bytes. It is useful when we work with systems or protocols that use a different byte order.Syntax of Character.reverseBytes() Methodpublic static char reverseBytes(char ch)Parameter: The function accepts one mandatory parameter, "ch" which signifies the character whose order of bytes is to be reversed. Returns: This method returns the value obtained by reversing (or, equivalently, swapping) the bytes in the specified char value.When to Use Character.reverseBytes() MethodWhen we work with systems that use different byte orders.When reading binary files or network data and byte alignment is important.For low-level optimizations in memory or protocol parsing.Examples of Java Character.reverseBytes() MethodExample 1: In this example, we are going to reverse the Unicode character bytes. Java // Java program to demonstrate // Character.reverseBytes() on a Unicode character import java.lang.Character; public class Geeks { public static void main(String[] args) { // character with Unicode value \u4d00 (two bytes) char ch1 = '\u4d00'; // reversing the byte order of the character char ch2 = Character.reverseBytes(ch1); System.out.println("Original char: " + ch1); System.out.println("After reversing bytes: " + ch2); } } OutputOriginal char: 䴀 After reversing bytes: M Example 2: In this example, we are going to reverse the bytes of digit characters. Java // Java program to demonstrate // Character.reverseBytes() on numeric characters import java.lang.Character; public class Geeks { public static void main(String[] args) { // reversing byte order of character '9' char ch1 = '9'; char reversed1 = Character.reverseBytes(ch1); System.out.println("Reversing bytes on '" + ch1 + "' gives: '" + reversed1 + "'"); // reversing byte order of character '7' char ch2 = '7'; char reversed2 = Character.reverseBytes(ch2); System.out.println("Reversing bytes on '" + ch2 + "' gives: '" + reversed2 + "'"); } } OutputReversing bytes on '9' gives: '㤀' Reversing bytes on '7' gives: '㜀' Note: The reversed values may appear as special Unicode symbols and depends on their byte combinations.Important Points:This method is very helpful for handling byte-level transformations of characters.It swaps the two bytes in a 16-bit char.The results may not always be a human readable character, because it depends on the Unicode value formed by the reversed bytes. Comment More infoAdvertise with us Next Article Comparator reversed() method in Java with examples T Twinkl Bajaj Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Character Practice Tags : Java Similar Reads Integer reverseBytes() Method in Java The java.lang.Integer.reverseBytes(int a) is a built-in method which returns the value obtained by reversing the order of the bytes in the two's complement representation of the specified int value. Syntax : public static int reverseBytes(int a) Parameter: The method takes one parameter a of integer 3 min read Integer reverse() Method In Java The java.lang.Integer.reverse() is an inbuilt method in Java and is used to return the reverse order of the bits in the two's complement binary representation of the specified int value. Syntax: public static int reverse(int a) Parameters: The parameter a is an integer value whose bits are to be rev 2 min read Array setByte() method in Java The java.lang.reflect.Array.setByte() is an inbuilt method in Java and is used to set a specified byte value to a specified index of a given object array. Syntax: Array.setByte(Object []array, int index, byte value) Parameter: This method takes 3 parameters: array: This is an array of type Object wh 3 min read Character.reverseBytes() in Java with examples The Character.reverseBytes() method in Java is a utility function from the java.lang.Character class. This method is used to reverse the order of the two bytes in a given 16-bit Unicode character (char). All Java characters are two bytes. It is useful when we work with systems or protocols that use 2 min read Comparator reversed() method in Java with examples The reversed() method of Comparator Interface in Java returns a comparator that imposes the reverse ordering of this comparator. If you use sort method of the array and passes this comparator after applying the reversed method then it will sort the array in reverse order. Syntax: default Comparator 2 min read Comparator reverseOrder() method in Java with examples The reverseOrder() method of Comparator Interface in Java returns a comparator that use to compare Comparable objects in reverse of natural order. The returned comparator by this method is serializable and throws NullPointerException when comparing null. Syntax: static <T extends Comparable<T 1 min read Collections.reverse() Method in Java with Examples The reverse() method of the Collections class, as the name suggests, is used to reverse the order of elements in a list. Note: It does not sort the elements, it simply reverses their current order.This class is present in java.util package so the syntax is as follows:import java.util.Collections;Col 3 min read StringBuffer reverse() Method in Java with Examples The Java.lang.StringBuffer.reverse() is an inbuilt method that is used to reverse the characters in the StringBuffer. The method causes this character sequence to be replaced by the reverse of the sequence. Syntax: public StringBuffer reverse() Parameters: NA Return Value: The method returns the Str 2 min read Java Guava | Lists.reverse() method with Examples Guava's Lists.reverse() method accepts a list as a parameter and returns a reversed view of the list passed as the parameter. If the specified list is random access, then the returned list is also random-access. For example: Lists.reverse(Arrays.asList(1, 2, 3)) returns a list containing 3, 2, 1. Sy 2 min read 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 2 min read Like