import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Main { public static void main(String[] argv) throws Exception { Set collection = new HashSet(); // For a set or list for (Iterator it = collection.iterator(); it.hasNext();) { Object element = it.next(); } } }