Java.lang.Character.getType() 方法
描述
java.lang.Character.getType(char ch) 返回一个值,表示字符的一般类别。
声明
以下是 java.lang.Character.getType() 方法的声明。
public static int getType(char ch)
参数
ch − 要测试的字符
返回值
此方法返回一个int类型的值,表示字符的一般类别。
异常
NA
示例
下面的例子展示了 lang.Character.getType() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
// create 2 character primitives ch1, ch2
char ch1, ch2;
// assign values to ch1, ch2
ch1 = 'M';
ch2 = '$';
// create 2 int primitives i1, i2
int i1, i2;
// assign getType values of ch1, ch2 to i1, i2
i1 = Character.getType(ch1);
i2 = Character.getType(ch2);
/**
* value 1 represents UPPERCASE_LETTER
* value 26 represents CURRENCY_SYMBOL
*/
String str1 = "Category of " + ch1 + " is " + i1;
String str2 = "Category of " + ch2 + " is " + i2;
// print i1, i2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Category of M is 1 Category of $ is 26

