// the following is the Iterator interface

public interface Iterator<E> {
    boolean hasNext();
    E next();
    void remove(); //optional
//the following method shows you how to use an Iterator to filter
//an arbitrary Collection: 

static void filter(Collection<?> c) {
    for (Iterator<?> it = c.iterator(); it.hasNext(); )
        if (!cond(

An Iterator is an object that enables you to traverse through a collection and to remove elements from the collection selectively, if desired. You get an Iterator for a collection by calling its iterator method.

Use Iterator instead of the for-each construct when you need to: remove the current element; iterate over multiple collections in parallel.

Iterator — Structure map

Clickable & Draggable!

Iterator — Related pages: