Computer >> Máy Tính >  >> Lập trình >> Java

Làm thế nào để tìm danh mục unicode cho một ký tự nhất định trong Java?

A Ký tự lớp là lớp con của Đối tượng và nó bao bọc một giá trị của kiểu nguyên thủy char trong một đối tượng. Đối tượng kiểu Ký tự chứa một trường duy nhất có kiểu là char . Chúng tôi có thể xác định danh mục unicode cho một ký tự cụ thể bằng cách sử dụng getType () phương pháp. Đây là một phương thức tĩnh của Ký tự lớp và nó trả về một số nguyên giá trị của char ch đại diện trong danh mục chung unicode.

Cú pháp

public static int getType(char ch)

Ví dụ

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'));
   }
}

Đầu ra

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