Java Character.isMirrored() Method
Last Updated :
14 May, 2025
The Character.isMirrored() method in Java is a built-in method of the java.lang.Character class. This method is used to check if a character is mirrored according to the Unicode specification. Mirrored characters are those whose glyphs are horizontally mirrored when displayed in right-to-left (RTL) text.
For example, the character "\u0028" LEFT PARENTHESIS is semantically defined to be an opening parenthesis. This will appears as "(" in text that is left-to-right (LTR) text, but it is displayed as ")" in RTL text. Some common mirrored characters include brackets like [ ], { }, and parentheses ( ).
Syntax of Character.isMirrored() Method
public static boolean isMirrored(char ch)
- Parameters: ch: The character for which the mirrored property is requested.
- Returns: This method returns "true" if the char is mirrored else it returns "false" if the character is not mirrored or undefined.
Examples of Java Character.isMirrored() Method
Example 1: In this example, we are going to check some common symbols.
Java
// Java program to check if characters
// are mirrored using isMirrored()
import java.lang.Character;
public class Geeks {
public static void main(String[] args) {
// Defining characters to test
char ch1 = '[';
char ch2 = '+';
char ch3 = '}';
char ch4 = '(';
// checking and printing whether
// each character is mirrored
System.out.println(ch1 + " is mirrored: "
+ Character.isMirrored(ch1));
System.out.println(ch2 + " is mirrored: "
+ Character.isMirrored(ch2));
System.out.println(ch3 + " is mirrored: "
+ Character.isMirrored(ch3));
System.out.println(ch4 + " is mirrored: "
+ Character.isMirrored(ch4));
}
}
Output[ is mirrored: true
+ is mirrored: false
} is mirrored: true
( is mirrored: true
Explanation: In this example, we can see that characters like "[" and "{" are mirrored but symbols like "+" are not considered mirrored.
Example 2: In this example, we are going to check digits and alphanumeric characters.
Java
// Java program to test digits and
// other characters for mirrored status
import java.lang.Character;
public class Geeks {
public static void main(String[] args) {
// defining digit characters
char ch1 = '4';
char ch2 = '0';
// checking and printing mirrored status
System.out.println(ch1 + " is mirrored: "
+ Character.isMirrored(ch1));
System.out.println(ch2 + " is mirrored: "
+ Character.isMirrored(ch2));
}
}
Output4 is mirrored: false
0 is mirrored: false
Explanation: Numbers and most letters are not mirrored characters in Unicode.
Important Points:
- This method is very helpful when we are designing applications that supports bidirectional (BiDi) text for languages like Arabic or Hebrew.
- It allows us to programmatically check if a character will need to be flipped horizontally in RTL environments.