Java-lang-character-charcount
提供:Dev Guides
Java.lang.Character.charCount()メソッド
説明
- java.lang.Character.charCount(int codePoint)*は、指定された文字(Unicodeコードポイント)を表すために必要なchar値の数を決定します。 指定された文字が0x10000以上の場合、メソッドは2を返します。 それ以外の場合、メソッドは1を返します。
このメソッドは、指定された文字が有効なUnicodeコードポイントであることを検証しません。 呼び出し元は、必要に応じてisValidCodePointを使用して文字値を検証する必要があります。
宣言
以下は* java.lang.Character.charCount()*メソッドの宣言です
public static int charCount(int codePoint)
パラメーター
*codePoint* -テストする文字(Unicodeコードポイント)
戻り値
このメソッドは、文字が有効な補助文字の場合は2を返し、そうでない場合は1を返します。
例外
NA
例
次の例は、lang.Character.charCount()メソッドの使用方法を示しています。
package com.finddevguides;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
//create and assign values to int codepoint cp
int cp = 0x12345;
//create an int res
int res;
//assign the result of charCount on cp to res
res = Character.charCount(cp);
String str1 = "It is not a valid supplementary character";
String str2 = "It is a valid supplementary character";
//print res value
if ( res == 1 ) {
System.out.println( str1 );
} else if ( res == 2 ) {
System.out.println( str2 );
}
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
It is a valid supplementary character