Interface LookaheadIterator<E>

All Known Implementing Classes:
PeekingIterator

public interface LookaheadIterator<E>
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the next element in iteration without advancing the underlying iterator.
    Returns the next element in iteration without advancing the underlying iterator.
  • Method Details

    • peek

      E peek()
      Returns the next element in iteration without advancing the underlying iterator. If the iterator is already exhausted, null will be returned.

      Note: this method does not throw a NoSuchElementException if the iterator is already exhausted. If you want such a behavior, use element() instead.

      The rationale behind this is to follow the Queue interface which uses the same terminology.

      Returns:
      the next element from the iterator
    • element

      E element()
      Returns the next element in iteration without advancing the underlying iterator. If the iterator is already exhausted, null will be returned.
      Returns:
      the next element from the iterator
      Throws:
      NoSuchElementException - if the iterator is already exhausted according to
      invalid reference
      #hasNext()