So I get that Java is a pass-by-copy language (at least as much as I've learned from the books so far). However, why does a code like that:
public static void main(String[] args) {
(...)
System.out.println("Array before sorting: "+Arrays.toString(ourArray));
System.out.println("Array after sorting: "+Arrays.toString(sortTheArray(ourArray)));
System.out.println("Bah-dum-tss: "+Arrays.toString(ourArray));
}
public static int[] sortTheArray(int[] someArray)
{
Arrays.sort(someArray);
return someArray;
}
Produce the same output for the second and third line? I mean - if we pass it by copy only, why doesn't it just print the sorted array on the second println and then print the same, non-sorted one on the third? I don't do any ourArray = sortTheArray(ourArray) anywhere so why does the value of it change? Thank you in advance and sorry for a newbish question :)