
Many times we need to iterate over the data structures. But should we allow our clients to know the internal details of the data-structure like whether it is using array or linked list and then iterate themselves.
Here's where java gives us the power called iterators which allows us to iterate over data structure.
Design Challenge
Consider the stack data structure and we want to support iteration over it on client side.
Step 1 - Make your stack ADT implement Iterable interface.
What is Iterable?
has a method that returns an Iterator.
public...