public class PushbackIterator<E> extends Objectimplements Iterator <E>
The decorator stores the pushed back elements in a LIFO manner: the last element that has been pushed back, will be returned as the next element in a call to next().
The decorator does not support the removal operation. Any call to remove() will result in an UnsupportedOperationException.
| Constructor and Description |
|---|
PushbackIterator(Iterator
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasNext()
|
E |
next()
|
void |
pushback(E item)
Push back the given element to the iterator.
|
static <E> PushbackIterator |
pushbackIterator(Iterator
Decorates the specified iterator to support one-element lookahead.
|
void |
remove()
This iterator will always throw an
UnsupportedOperationException.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic static <E> PushbackIterator<E> pushbackIterator(Iterator <? extends E> iterator)
If the iterator is already a PushbackIterator it is returned directly.
E - the element type
iterator - the iterator to decorate
NullPointerException - if the iterator is null
public void pushback(E item)
Calling next() immediately afterwards will return exactly this element.
item - the element to push back to the iterator
public boolean hasNext()
public E next()
public void remove()
UnsupportedOperationException.
remove in interface
Iterator<E>
UnsupportedOperationException - always