Since: API Level 1
public interface

Iterator

java.util.Iterator<E>
Known Indirect Subclasses

Class Overview

An Iterator is used to sequence over a collection of objects. Conceptually, an iterator is always positioned between two elements of a collection. A fresh iterator is always positioned in front of the first element. If a collection has been changed since its creation, methods next and hasNext() may throw a ConcurrentModificationException. Iterators with this behavior are called fail-fast iterators.

Summary

Public Methods
abstract boolean hasNext()
Returns whether there are more elements to iterate, i.e.
abstract E next()
Returns the next object in the iteration, i.e.
abstract void remove()
Removes the last object returned by next from the collection.

Public Methods

public abstract boolean hasNext ()

Since: API Level 1

Returns whether there are more elements to iterate, i.e. whether the iterator is positioned in front of an element.

Returns
  • true if there are more elements, false otherwise.
See Also

public abstract E next ()

Since: API Level 1

Returns the next object in the iteration, i.e. returns the element in front of the iterator and advances the iterator by one position.

Returns
  • the next object.
Throws
NoSuchElementException if there are no more elements.
See Also

public abstract void remove ()

Since: API Level 1

Removes the last object returned by next from the collection. This method can only be called once after next was called.

Throws
UnsupportedOperationException if removing is not supported by the collection being iterated.
IllegalStateException if next has not been called, or remove has already been called after the last call to next.