Package java.util
Interface Iterator<E>
-
- Type Parameters:
E- the type of object returned by the iterator.
- All Known Subinterfaces:
ListIterator<E>
public interface Iterator<E>An iterator over a sequence of objects, such as a collection.If a collection has been changed since the iterator was created, methods
nextandhasNext()may throw aConcurrentModificationException. It is not possible to guarantee that this mechanism works in all cases of unsynchronized concurrent modification. It should only be used for debugging purposes. Iterators with this behavior are called fail-fast iterators.Implementing
Iterableand returning anIteratorallows your class to be used as a collection with the enhanced for loop.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanhasNext()Returns true if there is at least one more element, false otherwise.Enext()Returns the next object and advances the iterator.voidremove()Removes the last object returned bynextfrom the collection.
-
-
-
Method Detail
-
hasNext
boolean hasNext()
Returns true if there is at least one more element, false otherwise.- Returns:
trueif there is a next element.- See Also:
next()
-
next
E next()
Returns the next object and advances the iterator.- Returns:
- the next object.
- Throws:
java.util.NoSuchElementException- if there are no more elements.- See Also:
hasNext()
-
remove
void remove()
Removes the last object returned bynextfrom the collection. This method can only be called once between each call tonext.- Throws:
java.lang.UnsupportedOperationException- if removing is not supported by the collection being iterated.java.lang.IllegalStateException- ifnexthas not been called, orremovehas already been called after the last call tonext.
-
-