Java examples for Collection Framework:Iterator
Iterate through a Collection using Iterator
import java.util.Iterator; import java.util.ArrayList; public class Main { public static void main(String[] args) { /* w w w .j ava 2s . c om*/ ArrayList aList = new ArrayList(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("5"); Iterator itr = aList.iterator(); while(itr.hasNext()) System.out.println(itr.next()); } }