Character.isMirrored() in Java with examples

java.lang.Character.isMirrored() is an inbuilt method in java that determines whether the character is mirrored according to the Unicode specification. Mirrored characters should have their glyphs horizontally mirrored when displayed in text that is right-to-left. For example, ‘\u0028’ LEFT PARENTHESIS is semantically defined to be an opening parenthesis. This will appear as a “(” in text that is left-to-right but as a “)” in text that is right-to-left. Some examples of mirrored characters are [ ] { } ( ) etc.

Syntax:

public static boolean isMirrored(char ch)

Parameters: 
ch - char 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.



Given below is the illustration of Character.isMirrored() method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate the
// Character.isMirrored() function
// When the character is a valid one.
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // Assign values to ch1, ch2, ch3, ch4
        char ch1 = '[';
        char ch2 = '+';
        char ch3 = '}';
        char ch4 = '(';
  
        // Checks if the character is mirrored or not and prints
        boolean b1 = Character.isMirrored(ch1);
        System.out.println(ch1 + " is a mirrored character is " + b1);
  
        boolean b2 = Character.isMirrored(ch2);
        System.out.println(ch2 + " is a mirrored character is " + b2);
  
        boolean b3 = Character.isMirrored(ch1);
        System.out.println(ch3 + " is a mirrored character is " + b3);
  
        boolean b4 = Character.isMirrored(ch2);
        System.out.println(ch4 + " is a mirrored character is " + b4);
    }
}

chevron_right


Output:

[ is a mirrored character is true
+ is a mirrored character is false
} is a mirrored character is true
( is a mirrored character is false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate the
// Character.isMirrored() function
// When the character is a invalid one.
import java.lang.*;
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // Assign values to ch1, ch2, ch3, ch4
        char ch1 = '4';
        char ch2 = '0';
  
        // Checks if the character is mirrored or not and prints
        boolean b1 = Character.isMirrored(ch1);
        System.out.println(ch1 + " is a mirrored character is " + b1);
  
        boolean b2 = Character.isMirrored(ch2);
        System.out.println(ch2 + " is a mirrored character is " + b2);
    }
}

chevron_right


Output:

4 is a mirrored character is false
0 is a mirrored character is false


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.