Java Character getType(char ch) 方法

2024年11月6日 | 阅读 4 分钟

Character 类的 getType(char ch) 方法返回一个表示该字符一般类别的整数值。此方法不用于增补字符。我们可以使用 getType(int codePoint) 方法来支持所有 Unicode 字符,包括增补字符。

语法

参数

ch: 需要测试的字符。

返回值

此方法返回一个 int 类型的值,表示该字符的一般类别。

示例 1

输出

The integer value for the character 2 is given as:
9
The integer value for the character { is given as:
21
The integer value for the character * is given as:
24
The integer value for the character @ is given as:
24
The integer value for the character $ is given as:
26

示例 2

输出

Enter the first input of your choice:{
The general category for the character { is given as: 21
Enter the second input of your choice:&
The general category for the character & is given as: 24

示例 3

输出

The general category of character 1 is: 9
The general category of character ! is: 24
The general category of character ) is: 22

Java Character getType(int codePoint) 方法

Character 类的 getType(int codePoint) 方法通常返回一个表示该字符一般类别的整数值。

语法

参数

codePoint: 需要测试的字符(Unicode codePoint)。

返回值

getType(int codePoint) 方法返回一个整数类型值,该值表示字符的一般类别。

示例 4

输出

The general category for the character X is given as: 1
The general category for the character n is given as: 2

示例 5

输出

The general category of the first character is given as: 24
The general category of the second character is given as: 2