天天看点

java三种数组拷贝方式

import java.util.Arrays;

public class ArrayCopy{

public static void main(String[] args) {

int[]x ={1,3,4,81,67,57,128,30};

int[]desc = new int[8];

System.out.println("System.arraycopy方法复制");

System.arraycopy(x, 0, desc, 0, x.length);

for (int i:desc){

System.out.print(i+" ");

}

System.out.println();

System.out.println("clone方法复制");

int[]desc1 =x.clone();

for (int i:desc1){

System.out.print(i+" ");

}

System.out.println("\n"+"copyOf方法复制");

int[]desc2 =Arrays.copyOf(x,x.length);

for (int i:desc2){

System.out.print(i+" ");

}

}

}

继续阅读