Java tutorial
import java.util.Iterator; /** * Adapt iterator to iterable * * @author Hong Hong * * @param Iterator type */ public class IteratorIterable<T> implements Iterable<T>, Iterator<T> { protected Iterator<T> m_itr; public IteratorIterable(Iterator<T> itr) { assert (itr != null); m_itr = itr; } public Iterator<T> iterator() { return m_itr; } public boolean hasNext() { return m_itr.hasNext(); } public T next() { return m_itr.next(); } public void remove() { m_itr.remove(); } }