Added in API level 1

Iterator

public interface Iterator

java.util.Iterator<E>


An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Framework. Iterators differ from enumerations in two ways:

  • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
  • Method names have been improved.

This interface is a member of the Java Collections Framework.

Summary

Public methods

default void forEachRemaining(Consumer<? super E> action)

Performs the given action for each remaining element until all elements have been processed or the action throws an exception.

abstract boolean hasNext()

Returns true if the iteration has more elements.

abstract E next()

Returns the next element in the iteration.

default void remove()

Removes from the underlying collection the last element returned by this iterator (optional operation).