Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util

Interface Iterator

java.lang.Object
|
+--java.util.Iterator


public interface Iterator

An object which iterates over a collection. An Iterator is used to return the items once only, in sequence, by successive calls to the next method. It is also possible to remove elements from the underlying collection by using the optional remove method. Iterator is intended as a replacement for the Enumeration interface of previous versions of Java, which did not have the remove method and had less conveniently named methods.

Since:Authors:See Also:

Method Summary

booleanhasNext()

Tests whether there are elements remaining in the collection.
java.lang.Objectnext()

Obtain the next element in the collection.
voidremove()

Remove from the underlying collection the last element returned by next (optional operation).

Method Details

hasNext

public boolean hasNext()

Tests whether there are elements remaining in the collection. In other words, calling next() will not throw an exception.

Returns:


next

public Object next()

Obtain the next element in the collection.

Returns:

Throws:


remove

public void remove()

Remove from the underlying collection the last element returned by next (optional operation). This method can be called only once after each call to next(). It does not affect what will be returned by subsequent calls to next.

Throws: