I first cloned 1D primitive array(It will hold wrappers) and then changed first value of the cloned array. But the first value of the original array was not changed. Then I cloned a 2D array and did the same.(changed the array[0][0] value).There the value was at originalArray[0][0] also was changed. Why this is happening. Is this due to shallow copy and deep copy?
My 1D array example
int[] arr=new int[2];
arr[0]=1;
arr[1]=2;
int[]arrnew=arr.clone();
System.out.println(arr[0]);
System.out.println(arrnew[0]);
arr[0]=5;
System.out.println(arr[0]);
System.out.println(arrnew[0]);
My 2D array example
int[][] arr=new int[2][2];
arr[0][0]=1;
arr[0][1]=2;
arr[1][0]=3;
arr[1][1]=4;
int[][] arrnew=arr.clone();
System.out.println(arr[1][0]);
System.out.println(arrnew[1][0]);
arr[1][0]=5;
System.out.println(arr[1][0]);
System.out.println(arrnew[1][0]);