import java.util.TreeSet;
public class TreeSetDemo {
public static void main(String[] argv) {
TreeSet tm = new TreeSet(String.CASE_INSENSITIVE_ORDER);
tm.add("Gosling");
tm.add("da Vinci");
tm.add("van Gogh");
tm.add("Java To Go");
tm.add("Vanguard");
tm.add("Darwin");
tm.add("Darwin"); // TreeSet is Set, ignores duplicates.
System.out.println("Lowest (alphabetically) is " + tm.first());
System.out.println(tm.tailSet("k").toArray().length+ " elements higher than \"k\"");
System.out.println("Sorted list:");
java.util.Iterator t = tm.iterator();
while (t.hasNext()){
System.out.println(t.next());
}
}
}