In Java, Character.isMirrored(ch) returns true when the character is mirrored: in right-to-left text such as Hebrew or Arabic, its glyph is drawn flipped. An opening parenthesis ( in Arabic text is displayed as ), so that it still "opens" in the reading direction.
Mirrored characters are mostly brackets and comparison symbols: ( ) < > [ ] { }, plus many math symbols such as U+2264 LESS-THAN OR EQUAL TO. Letters, digits, and most punctuation are not mirrored.
A static method of java.lang.Character (Java 1.4+): call it on the class, as in Character.isMirrored(...); you do not need a Character object. No import is needed, because java.lang is always available. The int codePoint overload was added in Java 5.
Unicode version.
The answer comes from the Unicode Character Database built into your JDK, and each Java release follows a specific Unicode version (Java 8, for example, uses Unicode 6.2). The characters used on this page have had the same properties for many Unicode versions, so the examples print the same result on any current JDK.
Syntax
Pass a char or an int code point.
Java
Character.isMirrored('('); // true
Character.isMirrored('<'); // true
Character.isMirrored('/'); // false
Character.isMirrored('a'); // false
Character.isMirrored('\u2264'); // true, LESS-THAN OR EQUAL TO
Call
What it does
Character.isMirrored(c)
Will this glyph flip in right-to-left text?
Character.isMirrored(s.codePointAt(i))
Same check by code point.
Character.getDirectionality(c)
The related bidirectional class.
Two overloads: isMirrored(char ch) since Java 1.4 and isMirrored(int codePoint) since Java 5. Java does not provide the mirrored partner; for ( you have to know it is ).
Library declarations
Java
// java.lang.Character
public static boolean isMirrored(char ch) // Java 1.4
public static boolean isMirrored(int codePoint) // Java 5
Parameters
Parameter
Description
ch (char)
The character to test.
codePoint (int)
A Unicode code point.
Return Value
Return Value
Description
true
The character has the Unicode Bidi_Mirrored property.
Paired brackets. Every kind of ASCII bracket is mirrored, both the opening and the closing form.
The slash is not.'/' looks directional, but Unicode does not mark it as mirrored.
Math symbols. U+2264 LESS-THAN OR EQUAL TO points in a direction, so like '<' it is mirrored.
Example 2 — Reverse a Formula and Swap Mirrored Characters
A toy right-to-left rendering: reverse the chars and replace each mirrored one with its partner.
Java
public class CharacterIsMirroredReverse {
static char partner(char c) {
switch (c) {
case '(': return ')';
case ')': return '(';
case '[': return ']';
case ']': return '[';
case '<': return '>';
case '>': return '<';
default: return c;
}
}
public static void main(String[] args) {
String s = "f(x) < [y]";
StringBuilder out = new StringBuilder();
int swapped = 0;
for (int i = s.length() - 1; i >= 0; i--) {
char c = s.charAt(i);
if (Character.isMirrored(c)) {
out.append(partner(c));
swapped++;
} else {
out.append(c);
}
}
System.out.println("reversed with mirroring: " + out);
System.out.println("mirrored chars swapped: " + swapped);
}
}
Output
reversed with mirroring: [y] > (x)f
mirrored chars swapped: 5
How It Works
Reverse first. Read backwards, "f(x) < [y]" becomes ]y[ < )x(f, where every bracket faces the wrong way.
Swap mirrored chars.isMirrored flags the four brackets and the less-than sign, and partner flips each one: [y] > (x)f.
Why it matters. This is the idea a renderer applies to right-to-left text, so that brackets still enclose the right part; real layouts use the full Unicode algorithm.
Example 3 — List Every Mirrored ASCII Character
Scan the ASCII range, then try two code points with the int overload.
Java
public class CharacterIsMirroredAscii {
public static void main(String[] args) {
StringBuilder found = new StringBuilder();
for (char c = 0; c < 128; c++) {
if (Character.isMirrored(c)) found.append(c);
}
System.out.println("mirrored ASCII: " + found + " (" + found.length() + ")");
System.out.println("U+2208 ELEMENT OF: " + Character.isMirrored(0x2208));
System.out.println("U+1F600 emoji: " + Character.isMirrored(0x1F600));
}
}