Character เป็นคลาสย่อยของ Object ห่อค่า primitive char ในออบเจ็กต์ มี field เดียวชนิด char สามารถหา unicode category ของตัวอักษรได้ด้วยเมธอด getType() เป็น static method ของ Character คืนค่า integer แทน unicode general category ของ 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