SortedSetExample.java

import java.util.*;
public class SortedSetExample {
  public static void main(String[] args) {
    SortedSet set = new TreeSet(new Point.XAxisComparator());
    set.add(new Point(4,0));
    set.add(new Point(1,0));
    set.add(new Point(1,1));
    set.add(new Point(1,0));
    set.add(new Point(2,0));
    for (Iterator it=set.iterator(); it.hasNext();)   // Affiche: (1,0) 
      System.out.println(it.next());                  //          (1,1)
                                                      //          (2,0)
                                                      //          (4,0)
    System.out.println(set.last());                   // Affiche: (4,0)
    SortedSet subset = set.subSet(new Point(1,1), new Point(4,0));
    for (Iterator it=subset.iterator(); it.hasNext();)// Affiche: (1,1)
      System.out.println(it.next());                  //          (2,0)  
  }
}