Interface LookaheadIterator<E>
-
- All Known Implementing Classes:
PeekingIterator
public interface LookaheadIterator<E>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description E
element()
Returns the next element in iteration without advancing the underlying iterator.E
peek()
Returns the next element in iteration without advancing the underlying iterator.
-
-
-
Method Detail
-
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, useelement()
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#hasNext()
-
-