Rob Prime wrote: . . . Use either clone() or System.arraycopy: . . .
As usual, Rob is right.
Remember the clone() method of an array returns a shallow clone, so it works best for an array with one  pair and immutable objects. If you have an array with more than one pair of  or which contains mutable objects, the individual elements are copied, not cloned, so a change in the 1st array will be reflected in the clone and vice versa.
The array elements themselves will be the same, but the arrays are definitely decoupled - on a first level.
Consider the following:
So after clone() or System.arraycopy, both arrays have the exact same contents - that includes references to the exact same objects. If you overwrite a reference (like on line 9) that only changes one array. If you change an element of one array (like on line 11), you change the object to which both arrays are referencing, and therefore the contents of both arrays change. Not the references inside the array, but the objects these references refer to.
Joined: Oct 13, 2005
No, that is not what I meant at all.
The clone of an array which contains mutable elements, ie mutable objects (which includes arrays, as in a  array), contains references to the original objects. If you sort the clone, the original array remains unchanged, but if you change the state of any elements, that element is in both arrays, and you can see the change from both references. Here's some code I thought up out of my head, and executed