Lớp Character là subclass của Object gói giá trị kiểu nguyên thủy char trong đối tượng. Đối tượng Character chứa một trường đơn kiểu char. Xác định unicode category cho ký tự cụ thể bằng phương thức getType(). Đây là phương thức static của Character trả về giá trị integer của char ch đại diện cho unicode general category.
Cú pháp
public static int getType(char ch)
Ví dụ
public class CharacterTypeTest {
public static void main(String args[]) {
System.out.println("T represents unicode category of: " + Character.getType('T'));
System.out.println("@ represents unicode category of: " + Character.getType('@'));
System.out.println(") represents unicode category of: " + Character.getType(')'));
System.out.println("1 represents unicode category of: " + Character.getType('1'));
System.out.println("- represents unicode category of: " + Character.getType('-'));
System.out.println("_ represents unicode category of: " + Character.getType('_'));
System.out.println("a represents unicode category of: " + Character.getType('a'));
}
}
Kết quả
T represents unicode category of: 1 @ represents unicode category of: 24 ) represents unicode category of: 22 1 represents unicode category of: 9 - represents unicode category of: 20 _ represents unicode category of: 23 a represents unicode category of: 2