import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class IteratorExample { public static void main(String[] args) { List list = new ArrayList<>(); list.add("One"); list.add("Two"); list.add("Three"); Iterator iterator = list.iterator(); while(iterator.hasNext()) { System.out.println(iterator.next()); } for (String string : list) { System.out.println(string); } } }