
The compareTo method of
the String class is discussed
in detail in Chapter 5.
REFERENCE POINT
8.6 Searching and Sorting Arrays 525
8.6.4 Sorting Arrays of Objects
We saw earlier in the chapter that data items to be sorted can be primitive
data types, such as integers or doubles. But they can also be objects. With an
array of objects, it is important to understand that we need to sort the
objects themselves, not the array elements, which are merely the object ref-
erences, or memory locations of the objects.
Arrays of objects are sorted using a sort key, which is one or more of the
instance variables of the objects. For instance, if we have email objects, ...