java数组拷贝

/**
 * Created by xabcd on 2019/2/13.
 */
public class java_arraycopy
{public static void main(String args[])
{
    int a1[]={1,2,3,4};
    int a2[] = {9,8,7,6,5,4,3,2};
    System.arraycopy(a1,0,a2,0,3);
    System.out.println("数组a1中的内容:");
    for (int i =0;i<a1.length;i++)
        System.out.print(a1[i]+"  ");
    System.out.println();
    System.out.println("数组a2中的内容:");
    for(int b = 0; b<a2.length;b++)
        System.out.print(a2[b]+"  ");
    System.out.print("数组打印完成");

}

}

System. arraycopy( source, 0, dest, 0, x) 语句 的 意思是: 复制 源 数组 从 下标 0 开始 的 x 个 元素 到 目标 数组, 从 目标 数组 的 下标 0 所 对应 的 位置 开始 存取。

 




结果:
数组a1中的内容:
1 2 3 4 
数组a2中的内容:
1 2 3 6 5 4 3 2 数组打印完成

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注