Java getChars() メソッド
getChars() メソッドは、文字列から文字をターゲット文字配列にコピーします。
構文
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
パラメータ
srcBegin-- 文字列内でコピーする最初の文字のインデックス。
srcEnd-- 文字列内でコピーする最後の文字の次のインデックス。
dst-- ターゲット配列。
dstBegin-- ターゲット配列内の開始オフセット。
戻り値
戻り値はありませんが、IndexOutOfBoundsException 例外をスローします。
例
public class Test {
public static void main(String args[]) {
String Str1 = new String("www.example.com");
char[] Str2 = new char[6];
try {
Str1.getChars(4, 10, Str2, 0);
System.out.print("拷贝的字符串为:" );
System.out.println(Str2 );
} catch( Exception ex) {
System.out.println("触发异常...");
}
}
}
上記のプログラムの実行結果は次のとおりです:
拷贝的字符串为:サンプル
その他の拡張
Java Stringクラス