Java-lang-character-gettype
提供:Dev Guides
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.finddevguides;
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