public class copyChar {
public static void main(String[] args){
/* String a = "abcdef";
String b = "helloword";*/
char a1[] = {'1','2','3','4','5'};
char b1[] = {'h','e','l','l','o',',','w','o','r'};
//System.arraycopy(a1,0, b1, 0,a1.length);
System.arraycopy(b1, 0, a1, 0, b1.length);
System.out.println(a1);
System.out.println(b1);
System.out.println(new String(a1));
System.out.println(new String(b1));
}
}
1) JAVA中的arraycopy()方法的使用
2) System.arraycopy的方法说明如下:
3) public static void arraycopy(Object src,int srcPos,Objectdest,int destPos,int length)
4) 参数:
5) src - 源数组。
6) srcPos - 源数组中的起始位置。
7) dest - 目标数组。
8) destPos - 目标数据中的起始位置。
9) length - 要复制的数组元素的数量。
由于数组大小问题,上述程序,结果是:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at copyChar.main(copyChar.java:9)