Top Description Methods
com.google.common.collect

public Interface PeekingIterator<E extends @Nullable Object>

extends Iterator<E extends @Nullable Object>
Known Direct Implementers
com.google.common.collect.TreeTraverser.BreadthFirstIterator, com.google.common.collect.Iterators.PeekingImpl
Annotations
@DoNotMock:Use Iterators.peekingIterator
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, com.google.errorprone.annotations.CanIgnoreReturnValue, .DoNotMock, java.util.Iterator, .NoSuchElementException, org.checkerframework.checker.nullness.qual.Nullable

An iterator that supports a one-element lookahead while iterating.

See the Guava User Guide article on PeekingIterator.

Author
Mick Killianey
Since
2.0

Method Summary

Modifier and TypeMethod and Description
public E
next()

Redeclares java.util.Iterator.next.

Returns the next element in the iteration.
public E
peek()

Returns the next element in the iteration, without advancing the iteration.

public void
remove()

Redeclares as abstract: java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.util.Iterator:
forEachRemaininghasNext

Method Detail

nextback to summary
public E next()

Redeclares java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

The objects returned by consecutive calls to peek() then next() are guaranteed to be equal to each other.

Returns:E

the next element in the iteration

Annotations
@CanIgnoreReturnValue
@Override
@ParametricNullness
peekback to summary
public E peek()

Returns the next element in the iteration, without advancing the iteration.

Calls to peek() should not change the state of the iteration, except that it may prevent removal of the most recent element via remove().

Annotations
@ParametricNullness
Exceptions
NoSuchElementException:
if the iteration has no more elements according to hasNext()
removeback to summary
public void remove()

Redeclares as abstract: java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Implementations may or may not support removal when a call to peek() has occurred since the most recent call to next().

Annotations
@Override
Exceptions
IllegalStateException:
if there has been a call to peek() since the most recent call to next() and this implementation does not support this sequence of calls (optional)