I do not understand why arrSort gets sorted too even if I did not declare it to be sorted?
arrSort1 = arrSort does not mean arrSort = arrSort1 right?
public static void main(String[] args) {
int[] arrSort = {4024, 4209, 9254, 8996, 9017, 6679, 3412, 6546, 2682, 42};
int[] arrSort1 = arrSort;
displayArray(arrSort);
displaySorted(arrSort1);
displayArray(arrSort);
}
public static void displayArray(int[] arrList){
for(int i = 0; i < arrList.length; i++)
System.out.print(arrList[i] + " ");
System.out.println();
}
public static void displaySorted(int[] arrSort1){
Arrays.sort(arrSort1);
for(int i = 0; i < arrSort1.length; i++){
System.out.print(arrSort1[i] + " ");
}
System.out.println();
}
The output says
4024 4209 9254 8996 9017 6679 3412 6546 2682 42
42 2682 3412 4024 4209 6546 6679 8996 9017 9254
42 2682 3412 4024 4209 6546 6679 8996 9017 9254