Interface Iterator<E>
- All Known Subinterfaces:
ListIterator<E>, PrimitiveIterator<T,T_CONS>, PrimitiveIterator.OfDouble, PrimitiveIterator.OfInt, PrimitiveIterator.OfLong
- All Known Implementing Classes:
Form.TabIterator
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.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidforEachRemaining(Consumer<? super E> action) Hands each remaining element toaction, in order.booleanhasNext()Returns whether there are more elements to iterate, i.e.next()Returns the next object in the iteration, i.e.default voidremove()Removes the last elementnextanswered from the collection being iterated, which this iterator does not support unless it says otherwise.
-
Method Details
-
hasNext
boolean hasNext()Returns whether there are more elements to iterate, i.e. whether the iterator is positioned in front of an element.
Returns
trueif there are more elements,falseotherwise.See also
- #next
-
next
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
- #hasNext
-
remove
default void remove()Removes the last element
nextanswered from the collection being iterated, which this iterator does not support unless it says otherwise.Throws
-
UnsupportedOperationException: when removing is not supported -
IllegalStateException: whennexthas not been called, orremovehas already been called after the last call tonext
-
-
forEachRemaining
-