Java-lang-character-codepointbefore-sequence
提供:Dev Guides
Java.lang.Character.codePointBefore()メソッド
説明
- java.lang.Character.codePointBefore(CharSequence seq、int index)*は、CharSequenceの指定されたインデックスの前のコードポイントを返します。 CharSequenceの(index-1)のchar値が低サロゲート範囲にある場合、(index-2)は負ではなく、CharSequenceの(index-2)のchar値は高サロゲート範囲にあります、このサロゲートペアに対応する補助コードポイントが返されます。
それ以外の場合、(index-1)のchar値が返されます。
宣言
以下は* java.lang.Character.codePointBefore()*メソッドの宣言です
public static int codePointBefore(CharSequence seq, int index)
パラメーター
- seq -CharSequenceインスタンス
- index -返されるコードポイントに続くインデックス
戻り値
このメソッドは、指定されたインデックスの前のUnicodeコードポイント値を返します。
例外
- NullPointerException -aがnullの場合。
- IndexOutOfBoundsException -インデックス引数が1より小さいか、seq.length()より大きい場合
例
次の例は、lang.Character.codePointBefore()メソッドの使用方法を示しています。
package com.finddevguides;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
//create a CharSequence seq and assign value
CharSequence seq = "Hello";
//create and assign value to index
int index = 4;
//create an int res
int res;
//assign result of codePointBefore on seq at index to res
res = Character.codePointBefore(seq, index);
String str = "Unicode code point is " + res;
//print res value
System.out.println( str );
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Unicode code point is 108