SE450
:
The Comparator interface type
[16/41]
How can we sort countries by name?
Can't implement
Comparable
twice!
Comparator
interface type gives added flexibility
public interface Comparator<T>
{
int compare(T obj1, T obj2);
}
Pass comparator object to
sort
:
Collections.sort(list, comp);