March 2002
Intermediate to advanced
496 pages
8h 51m
English
The ITERATOR pattern (see Chapter 28, Iterator) provides a way to access the elements of collection sequentially. But iterator() methods themselves are usually good examples of the FACTORY METHOD pattern. An iterator() method isolates its caller from knowing which class to instantiate. The Java JDK version 1.2 release introduced the Collection interface, which includes the iterator() operation. All collections implement this operation.
An iterator() method creates an object that returns a sequence of the elements of a collection. For example, the following code creates and prints out the elements of a list:
package com.oozinoz.applications;
import java.util.*;
public class ShowIterator { public ...Read now
Unlock full access