Interface Comparator


public interface Comparator

This interface represents function prototype for a comparison function, which imposes a total ordering on some collection of objects.

It is used for example to sort a collection. A callback function with the exact signature as compare(Object, Object) is given to the sorting function and is then used to determine the order of elements.

See Also:
Callbacks, List.sort(Comparator)

Method Summary
 int compare(Object o1, Object o2)
          Compares its two arguments for order.
 

Method Detail

compare

int compare(Object o1,
            Object o2)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
   if (o1 <  o2) return -1; 
   if (o1 == o2) return  0;
   if (o1 >  o2) return  1; 
 

Parameters:
o1 - the first object to be compared.
o2 - the second object to be compared.