Java-lang-character-codepointcount
提供:Dev Guides
Java.lang.Character.codePointCount()メソッド
説明
- java.lang.Character.codePointCount(char [] a、int offset、int count)*は、char配列引数のサブ配列内のUnicodeコードポイントの数を返します。
offset引数はサブ配列の最初の文字のインデックスであり、count引数はサブ配列の長さを文字数で指定します。 サブアレイ内のペアになっていないサロゲートは、それぞれ1つのコードポイントとしてカウントされます。
宣言
以下は* java.lang.Character.codePointCount()*メソッドの宣言です
public static int codePointCount(char[] a, int offset, int count)
パラメーター
- a -文字配列
- offset -指定されたchar配列の最初のcharのインデックス
- count -文字の部分配列の長さ
戻り値
このメソッドは、指定されたサブ配列内のUnicodeコードポイントの数を返します。
例外
- NullPointerException -aがnullの場合。
- IndexOutOfBoundsException -offsetまたはcountが負の場合、またはoffset + countが指定された配列の長さより大きい場合
例
次の例は、lang.Character.codePointCount()メソッドの使用方法を示しています。
package com.finddevguides;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
//create a char array c and assign values
char[] c = new char[] { 'a', 'b', 'c', 'd', 'e' };
//create and assign value to offset, count
int offset = 1, count = 3;
//create an int res
int res;
//assign result of codePointCount on subarray of c to res
res = Character.codePointCount(c, offset, count);
String str = "No. of Unicode code points is " + res;
//print res value
System.out.println( str );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
No. of Unicode code points is 3