Interface PeekingIterator<E extends @Nullable java.lang.Object>

  • All Superinterfaces:
    java.util.Iterator<E>

    @DoNotMock("Use Iterators.peekingIterator")
    @GwtCompatible
    public interface PeekingIterator<E extends @Nullable java.lang.Object>
    extends java.util.Iterator<E>
    An iterator that supports a one-element lookahead while iterating.

    See the Guava User Guide article on PeekingIterator.

    Since:
    2.0
    Author:
    Mick Killianey
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      E next()
      E peek()
      Returns the next element in the iteration, without advancing the iteration.
      void remove()
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, hasNext
    • Method Detail

      • peek

        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().

        Throws:
        java.util.NoSuchElementException - if the iteration has no more elements according to Iterator.hasNext()
      • remove

        void remove()

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

        Specified by:
        remove in interface java.util.Iterator<E extends @Nullable java.lang.Object>
        Throws:
        java.lang.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)