Iterator Interface
Package: java.util
An iterator is a special type of object whose sole purpose in life is to let you step through the elements of a collection. If you want to build a class that can be processed by the Java enhanced for
statement (also known as “foreach”), the class must implement the Iterator
class and provide an iterator
method, which in turn must return an object that implements the Iterator
class. This class must implement each of the three methods listed in the following table.
Methods
Method |
Explanation |
|
Returns |
|
Returns the next element in the collection. |
|
Removes the most recently retrieved element. |