4、JAVA中字符串的拷贝、arraycopy()的用法

来源:互联网 发布:鑫居安消防手电筒 淘宝 编辑:程序博客网 时间:2024/05/17 04:44
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)


原创粉丝点击