Comparable Interface
Home ] Up ] [ Comparable Interface ] Comparator Interface ] Collections Class ] Comparable Example ] Comparator Example ] General Applicability ]

 

 

The Comparable interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.

Collection
    List
    Set
        SortedSet
Comparable (in java.lang package)
Comparator
Enumeration
Iterator
    ListIterator
Map
    SortedMap

Comparable defines the following methods:

package java.lang;

public interface Comparable 
{
    public int compareTo(Object o);
}

where the compareTo method returns:

  • a negative integer if this object is less then the specified object
  • zero if this object is equal to the specified object
  • a positive integer if this object greater than the specified object.
 

This page was last modified on 02 October, 2007