IteratorsA common operation is traversal of all elements of a collection. An iterator is an object that allows you to do so in a simple way.The java.util.Iterator interface provides the following methods:
The java.util.Scanner class is an example of a class that implements the Iterator interface. The following piece of code reads the text of a file one word at a time.
|