Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Iterator

public interface Iterator

java.util.Iterator<E>
Known Indirect Subclasses


An iterator over a sequence of objects, such as a collection.

If a collection has been changed since the iterator was created, methods next and hasNext() may throw a ConcurrentModificationException. 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 Iterable and returning an Iterator allows your class to be used as a collection with the enhanced for loop.

Summary

Public methods

abstract boolean hasNext()

Returns true if there is at least one more element, false otherwise.

abstract E next()

Returns the next object and advances the iterator.

abstract void remove()

Removes the last object returned by next from the collection.

Public methods

hasNext

Added in API level 1
boolean hasNext ()

Returns true if there is at least one more element, false otherwise.

Returns
boolean

See also:

next

Added in API level 1
E next ()

Returns the next object and advances the iterator.

Returns
E the next object.
Throws
NoSuchElementException if there are no more elements.

See also:

remove

Added in API level 1
void remove ()

Removes the last object returned by next from the collection. This method can only be called once between each call to next.

Throws
UnsupportedOperationException if removing is not supported by the collection being iterated.
IllegalStateException if next has not been called, or remove has already been called after the last call to next.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.