previous | start | next

Sorting Arrays of Arbitray Element Type

Well, not arbitrary, there must be an ordering on the values of the element type.

For class types that implement the Comparable interface, the compareTo method provides an ordering.

Existing Java API classes that have a natural ordering (what's that?) implement Comparable:

That String implements Comparable<String> means that the String class has a compareTo method where the generic type parameter E is String:

      public class String implements Comparable<String>
      {
         ...
         public int compareTo(String other) { 
           ...
         }
   


previous | start | next