1// Shallow copy
2int[] src = {1,2,3,4,5};
3int[] dst = Arrays.copyOf(src, src.length);
4
5// Deep copy
6int[] dst2 = new int[src.length];
7for(int i = 0; i < src.length; i++){
8 dst2[i] = src[i];
9}
1int[] src = new int[]{1,2,3,4,5};
2int[] dest = new int[5];
3
4System.arraycopy( src, 0, dest, 0, src.length );
1// method
2public static int [] copyArray(int [] arr){
3 int [] copyArr = new int[arr.length];
4 for (int i = 0; i < copyArr.length; i++){
5 copyArr[i] = arr[i];
6 }
7 return copyArr;
8}
9
10// Arrays. method
11int[] copyCat = Arrays.copyOf(arr, arr.length);
12
13// System
14System.arraycopy(x,0,y,0,5); // 5 is array's length
15
16// clone
17y = x.clone();