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