Java Character.isMirrored()方法
Character.isMirrored(int codePoint) 是java中的一个内置方法,它根据Unicode规范确定指定的字符(Unicode码位)是否是镜像的。镜像字符在从右到左的文本中显示时,其字形应该是水平镜像的。例如,’\u0028′ LEFT PARENTHESIS在语义上被定义为一个开口括号。这在从左到右的文本中会显示为”(“,但在从右到左的文本中则显示为”)”。
语法
public static boolean isMirrored(int codePoint)
参数: 整数类型的参数codePoint是要测试的字符(Unicode码位)。
返回值: 如果该字符是镜像的,该方法返回true;如果该字符不是镜像的或未定义,则返回false。
下面的程序说明了Character.isMirrored()方法。
程序1 :
// Code to illustrate the isMirrored() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Creating 2 int primitives char1, char2
int char1 = 0x0c05, char2 = 0x013c;
// Checks if character is mirrored or not and prints
boolean bool1 = Character.isMirrored(char1);
String str1 = "char1 represents a mirrored character is " + bool1;
System.out.println(str1);
boolean bool2 = Character.isMirrored(char2);
String str2 = "char2 represents a mirrored character is " + bool2;
System.out.println(str2);
}
}
输出。
char1 represents a mirrored character is false
char2 represents a mirrored character is false
程序2
// Code to illustrate the isMirrored() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create 2 int primitives c1, c2
int c1 = 0x0c07, c2 = 0x063c;
// Checks if character is mirrored or not and prints
boolean bool1 = Character.isMirrored(c1);
String str1 = "c1 represents a mirrored character is " + bool1;
System.out.println(str1);
boolean bool2 = Character.isMirrored(c2);
String str2 = "c2 represents a mirrored character is " + bool2;
System.out.println(str2);
}
}
输出。
c1 represents a mirrored character is false
c2 represents a mirrored character is false
参考资料: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isMirrored(int)