Iterator Design Pattern in Java – Example Tutorial

About Pankaj Kumar

Iterator pattern in one of the behavioral pattern and it’s used to provide a standard way to traverse through a group of Objects. Iterator pattern is widely used in Java Collection Framework where Iterator interface provides methods for traversing through a collection. According to GoF, iterator design pattern intent is:

Provides a way to access the elements of an aggregate object without exposing its underlying represenation.

Iterator pattern is not only about traversing through a collection, we can provide different kind of iterators based on our requirements. Iterator pattern hides the actual implementation of traversal through the collection and client programs just use iterator methods.

Let’s understand this pattern with a simple example. Suppose we have a list of Radio channels and the client program want to traverse through them one by one or based on the type of channel, for example some client programs are only interested in English channels and want to process only them, they don’t want to process other types of channels.


Source : http://www.javacodegeeks.com/2013/08/iterator-design-pattern-in-java-example-tutorial.html

Back to Top