如何在 Java 中查找给定字符的 unicode 类别?
javaobject oriented programmingprogramming更新于 2024/5/10 21:15:00
Character 类是 Object 的子类,它将原始类型 char 的值包装在对象中。Character 类型的对象包含一个类型为 char 的字段。我们可以使用 getType() 方法确定特定字符的 unicode 类别。它是 Character 类的静态方法,它返回一个表示 unicode 一般类别的 char ch 的 整数 值。
语法
public static int getType(char ch)
示例
public class CharacterTypeTest { public static void main(String args[]) { System.out.println("T represnts unicode category of: " + Character.getType('T')); System.out.println("@ represnts unicode category of: " + Character.getType('@')); System.out.println(") represnts unicode category of: " + Character.getType(')')); System.out.println("1 represnts unicode category of: " + Character.getType('1')); System.out.println("- represnts unicode category of: " + Character.getType('-')); System.out.println("_ represnts unicode category of: " + Character.getType('_')); System.out.println("a represnts unicode category of: " + Character.getType('a')); } }
输出
T represnts unicode category of: 1 @ represnts unicode category of: 24 ) represnts unicode category of: 22 1 represnts unicode category of: 9 - represnts unicode category of: 20 _ represnts unicode category of: 23 a represnts unicode category of: 2