Java 教程
getChars() 方法將字符從字符串復(fù)制到目標(biāo)字符數(shù)組。
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
srcBegin -- 字符串中要復(fù)制的第一個(gè)字符的索引。
srcEnd -- 字符串中要復(fù)制的最后一個(gè)字符之后的索引。
dst -- 目標(biāo)數(shù)組。
dstBegin -- 目標(biāo)數(shù)組中的起始偏移量。
沒有返回值,但會(huì)拋出 IndexOutOfBoundsException 異常。
public class Test { ????public static void main(String args[]) { ????????String Str1 = new String(""); ????????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í)行結(jié)果為:
拷貝的字符串為:json