go to previous page   go to home page   go to next page
String temp = strArray[5];
strArray[5] = strArray[3];
strArray[3] = temp;

Answer:

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.


Sorting an Array of String References

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.

array of string references
array of string references

Now the sorting procedure must rearrange the references in the cells based on the Strings they point to.


QUESTION 4:

In the original array (on the left), should references in the first two cells of the array be swapped?


go to previous page   go to home page   go to next page