String temp = strArray[5]; strArray[5] = strArray[3]; strArray[3] = temp;
These statements swap the value in cell number 3 with the value in cell number 5.
Now cell 3 points to the object that contains "ibx" and cell 5 points to the object that contains "cat".
The objects themselves just sit in memory, unchanged.
Say that you have an array of String references (as on the left) and you wish to rearrange the references so that the Strings are in order (as on the right). In other words, visiting the cells in ascending order of the index should access the Strings in ascending order. The Strings themselves remain in their original memory locations.
Now the sorting procedure must rearrange the references in the cells based on the Strings they point to.
In the original array (on the left), should references in the first two cells of the array be swapped?