Background
I am making an array tools class for adding Python functionality to a Java array, and I came across this problem. This is obviously a simplified, more universal version.
Question
In this example:
public class ArrayTest
{
public static void main(String[] args)
{
// initial setup
int[] given = {1, 2, 3, 4, 5};
// change array
int[] changed = adjust(given);
// these end up being the same...
System.out.println(Arrays.toString(changed));
System.out.println(Arrays.toString(given));
}
private static int[] adjust(int[] a)
{
for (int i = 0; i < a.length; i++)
{
a[i]++;
}
return a;
}
}
...why is changed
and given
the same thing?
Disclaimer
I am guessing that this has been asked before, but I couldn't find an answer, so I apologize for that.