java.lang.Character isMirrored(char ch)

Description

The Character.isMirrored(char ch) java method 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.

This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isMirrored(int) method.

The isMirrored(char ch) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

Character.isMirrored(char ch)

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java isMirrored() method non statically.

Method Syntax

public static boolean isMirrored(char ch)

Method Argument

Data Type Parameter Description
char ch char for which the mirrored property is requested

Method Returns

The isMirrored(char ch) method of Character class returns true if the char is mirrored, false if the char is not mirrored or is not defined.

Compatibility

Requires Java 1.4 and up

Java Character isMirrored(char ch) Example

Below is a simple java example on the usage of isMirrored(char ch) method of Character class.

package com.javatutorialhq.java.examples;

import java.util.Scanner;

/*
 * This example source code demonstrates the use of 
 * isMirrored(char ch) method of Character class.
 */

public class CharacterIsMirroredCharExample {

	public static void main(String[] args) {

		/*
		 * Example: ( ) ] [ { }"
		 */
		
		// Ask for user input
		System.out.print("Enter a character:");

		// use scanner to get the user input
		Scanner s = new Scanner(System.in);

		// get a single character
		char[] values = s.nextLine().toCharArray();

		// close the scanner object
		s.close();

		for (char ch : values) {
			// check if the user input is mirrored or not
			boolean checkBool = Character.isMirrored(ch);

			// print result
			if (checkBool) {
				System.out.println("User input '" + ch + "' is mirrored");
			} else {
				System.out.println("User input '" + ch + "' is not mirrored");
			}
		}

	}

}

Sample Output

Below is the sample output when you run the above example.

java Character isMirrored(char ch) example output