java中getchars方法_Java getChars() 方法
getChars() 方法將字符從字符串復制到目標字符數(shù)組。
語法
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
參數(shù)
srcBegin -- 字符串中要復制的第一個字符的索引。
srcEnd -- 字符串中要復制的最后一個字符之后的索引。
dst -- 目標數(shù)組。
dstBegin -- 目標數(shù)組中的起始偏移量。
返回值
沒有返回值,但會拋出 IndexOutOfBoundsException 異常。
實例
public class Test {
public static void main(String args[]) {
String Str1 = new String("www.runoob.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("觸發(fā)異常...");
}
}
}
以上程序執(zhí)行結果為:
拷貝的字符串為:runoob
總結
以上是生活随笔為你收集整理的java中getchars方法_Java getChars() 方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 曲线抽稀 java_Python实现曲线
- 下一篇: java美元兑换,(Java实现) 美元