import java.util.*;
public class copyArray {
public static void main(String[] args) {
int[] e = {4,5,2,7,8};
int[] f;
f = Arrays.copyOf(e,3);// input 0-2
for (int k = 0; k < f.length; k++) {
System.out.print(f[k]+" ");
}
System.out.println();
int[] a = {1, 2, 3, 4};
int[] b = new int[10];
b = Arrays.copyOfRange(a, 0, 4);
for(int i = 0; i < 4; i++)
System.out.print(b[i]+" ");
System.out.println();
int[] c = {4,5,2,7,8};
int[] d;
d = c.clone();
for (int j = 0; j < d.length; j++) {
System.out.print(d[j]+" ");
}
System.out.println();
int[] g = {4,8,6,3,4,56};
int[] h = new int[10];
System.arraycopy(g,2,h,3,4);//A starts from 2 and copies from 0-3 to B starts from 3
for (int n = 0; n < h.length; n++) { //a从2开始往后0-3复制到b从3开始放入
System.out.print(h[n]+" ");
}
}
}
输出结果: