Iterator java code example
Example 1: java iterator example
Iterator iterator = list.iterator();
System.out.println("List elements : ");
while (iterator.hasNext())
System.out.print(iterator.next() + " ");
Example 2: python iterator
pies = ["cherry", "apple", "pumpkin", "pecan"]
iterator = iter(pies)
print(next(iterator))
#prints "cherry" because it's the current one being iterated over