Sorting and Searching Arrays of Objects Using Comparator
The Arrays class
contains a sort method that can sort array of objects that
implement the Comparator interface
The Comparator
interface
public interface Comparator
{
public int compare( Object firstObject, Object secondObject);
}
If comp is a Comparator object, then the call
comp.compare(a, b)
- Returns a negative number if a should come before
b
- Returns 0 if a and b are the same
- Returns a positive number otherwise