import java.util.ArrayList; import java.util.Iterator; public class IteratorExample { public static void main(String[] args) { ArrayListIn this example, we create an ArrayList of String objects and add three names to it. We then create an Iterator and iterate over the collection using the hasNext() and next() methods to print each name. The java.util package provides the Iterator interface.names = new ArrayList<>(); names.add("John"); names.add("Jane"); names.add("Bob"); Iterator iterator = names.iterator(); while (iterator.hasNext()) { String name = iterator.next(); System.out.println(name); } } }