0
We can use loops instead of using iterators. then what is need of Iterators??
2 Answers
+ 5
there are cases where for loop can't be used. For instance with a set, you can't have a direct access to elements. The only way is then to use an iterator.
+ 1
Most of the time we use iterators for collection, in order to travers one object at a time. And at the same time, we can also use enhanced for loop to travers the objects in a collection. Both of these can be used based on the requirement. In order to access the elements of collection, you have to use iterators inside the loops.