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