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.w3big.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("触发异常..."); } } }
上記プログラムの実行結果:
拷贝的字符串为:w3big