Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public interface Iterator<E>
Known subtypesListIterator, PrimitiveIterator, PrimitiveIterator.OfDouble, PrimitiveIterator.OfInt, PrimitiveIterator.OfLong
An Iterator is used to sequence over a collection of objects.
Conceptually, an iterator is always positioned between two elements of a
collection. A fresh iterator is always positioned in front of the first
element.
If a collection has been changed since its creation, methods next and
hasNext() may throw a ConcurrentModificationException.
Iterators with this behavior are called fail-fast iterators.
Type parameter E: the type of object returned by the iterator.
Methods
public abstract boolean hasNext() | Returns whether there are more elements to iterate, i.e. whether the iterator is positioned in front of an element. |
public abstract E next() | Returns the next object in the iteration, i.e. returns the element in front of the iterator and advances the iterator by one position. |
public default void remove() | Removes the last element next answered from the collection being iterated, which this iterator does not support unless it says otherwise. |
public default void forEachRemaining(Consumer<? super E> action) | Hands each remaining element to action, in order. |
Method details
hasNext
public abstract boolean hasNext()Returns whether there are more elements to iterate, i.e. whether the
iterator is positioned in front of an element.
Returns
true if there are more elements, false otherwise.See also
next
public abstract E next()Returns the next object in the iteration, i.e. returns the element in
front of the iterator and advances the iterator by one position.
Returns
the next object.
Throws
NoSuchElementException- if there are no more elements.
See also
remove
public default void remove()Removes the last element
next answered from the collection being
iterated, which this iterator does not support unless it says otherwise.Throws
UnsupportedOperationException- when removing is not supported
IllegalStateException- when
nexthas not been called, orremovehas already been called after the last call tonext
forEachRemaining
public default void forEachRemaining(Consumer<? super E> action)Hands each remaining element to
action, in order.