previous | start | next

Iterator Interface

public interface Iterator<E>
{
   public boolean hasNext();
   public E next();
   public void remove(); // optional; i.e., can just throw an exception
}
Example
ArrayList<Integer> lst = new ArrayList<Integer>();
for(int i = 0; i < 10; i++) {
   lst.add(i);
}

Iterator<Integer> it = lst.iterator();

while(it.hasNext()) {
  System.out.println(it.next());
}


previous | start | next