如何在Java中查找给定字符的unicode类别?


本文向大家介绍如何在Java中查找给定字符的unicode类别?,包括了如何在Java中查找给定字符的unicode类别?的使用技巧和注意事项,需要的朋友参考一下

字符 类是一个的子类对象 ,并将其在对象包装基本类型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