The Iterator interface has the following methods:
Compared to an Enumeration, hasNext() is equivalent to hasMoreElements() and next() equates to nextElement().
import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class MainClass { public static void main(String[] a) { Collection c = new ArrayList(); c.add("1"); c.add("2"); c.add("3"); Iterator i = c.iterator(); while (i.hasNext()) { System.out.println(i.next()); } } }
1 2 3