r/javaexamples • u/Shilpa_Opencodez • Jul 25 '19
Java Behavioral Design Patterns - Iterator Design Pattern
Iterator Design Pattern is one of the Behavioural design patterns in Java. It is used for traversing through the collection of data in a particular class.
This pattern hides the actual implementation of traversal through the collection. The application programs just use iterator methods for different purposes. Iterator pattern allows accessing the elements of a collection object in a sequential manner without knowledge of its structure. Key points to remember about this interface are:
This pattern is used when you foresee a collection is traversed with different types of criteria.
The collection object should be accessed and traversed without exposing its data structure.
New traversal operations should be defined for collection object without changing its interface.