TreeSetTest.java |
/* * TreeSetTest.java * * Created on December 4, 2002 */ package collections.treeset; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; /** * Demonstrates how to add objects to a TreeSet * and retrieve them. * @author Thomas Rowland */ public class TreeSetTest { public static void main(String[] args) { Set ts = new TreeSet(); ts.add("Jerry"); ts.add("Bob"); ts.add("Phil"); // Print out all names Iterator i = ts.iterator(); while (i.hasNext()) System.out.println((String) i.next()); } }