Java String getChars()
方法將此字串中的字元複製到目標字元數組中。
語法
以下是此方法的語法 -
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
參數
srcBegin
- 要複製的字串中第一個字元的索引。srcEnd
- 要複製的字串中最後一個字元後面的索引。dst
- 目標數組。dstBegin
- 目標數組中的起始偏移量。
返回值
- 它不返回任何值,但可能會拋出
IndexOutOfBoundsException
。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("Welcome to xuhuhu.com");
char[] Str2 = new char[7];
try {
Str1.getChars(8, 15, Str2, 0);
System.out.print("Copied Value = ");
System.out.println(Str2);
} catch (Exception ex) {
System.out.println("Raised exception...");
}
}
}
執行上面示例代碼,得到以下結果:
Copied Value = to Yiib
上一篇:
Java String類
下一篇:
Java快速入門