tree set java extend sorted set code example
Example 1: TreeSet
TreeSet ensemble = new TreeSet();
Comparator comparateur = new Comparateur();
TreeSet ensemble = new TreeSet(comparateur);
public class Comparateur implements Comparator {
public int compare(Object obj1, Object obj2){
return ((Comparable)obj2).compareTo(obj1);
}
public boolean equals(Object obj){
return this.equals(obj);
}
}
Example 2: treeset
TreeSet: Can contain only unique values and it is sorted in ascending order
TreeMap: Can contain only unique keys and keys are sorted in ascending order.