ตัวละคร class เป็นคลาสย่อยของ Object และรวมค่าของถ่านประเภทดั้งเดิมไว้ในวัตถุ วัตถุประเภท Character มีฟิลด์เดียวที่มีประเภทเป็น ถ่าน . เราสามารถกำหนดหมวดหมู่ Unicode สำหรับอักขระเฉพาะได้โดยใช้ getType() กระบวนการ. มันเป็นวิธีการคงที่ของ ตัวละคร class และส่งคืน จำนวนเต็ม ค่าของถ่าน ch เป็นตัวแทนในหมวดหมู่ทั่วไปของ Unicode
ไวยากรณ์
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