The Iterator pattern allows you to navigate through a collection of data using a common interface without knowing about the underlying implementation.
To accomplish this, the Iterator pattern suggests that a Container object should be designed to provide a public interface in the form of an Iterator object for different client objects to access its contents. Example iterators in Java are ResultSet, java.util.Iterator, Enumeration,…They usually have methods such as boolean hasMoreElements() and Object nextElement().
We usually have two types of iterator:
- Internal Iterator:
The collection itself offers methods to allow a client to visit different objects within the collection. For example ResultSet. Usually collection extends or implements an iterator. Your custom collection(e.g. Personnel) can also implement Iterator interface.
- External Iterator:
The iteration functionality is separated from the collection and kept inside a different object referred to as an iterator. In most cases the iterator can simply implement java.util.Iterator. Usually, the collection itself returns an appropriate iterator. For example, the java.util.Vector.elements() method returns an Enumeration.





