Iterating in Java

This lesson introduces questions relating to iteration in Java.

We'll cover the following...

Question # 1

What is the difference between Iterator and Iterable interfaces?

The Iterator interface is implemented by collection classes that intend to provide a uniform way of accessing their items sequentially.

public interface Iterator<E> {
    boolean hasNext();

    E next();

    void remove();
}

The Iterable interface on the other hand is implemented by classes that can be the target of the foreach statement or in other words can produce an iterator. The ...