We don’t re-implement wheel, so Java collection framework offers very easy way to iterate the elements. But iterator pattern is useful, you need to handle it. Everyday you use it but have you though how it works? read the example.

Iterator Design Pattern in Java  (this example forgot to implement Iterable interface. The Iterable interface has only one method:  iterator)

Java’s Iterators and Iterables

Also the beginner may get this exception,  ConcurrentModificationException because if you don’t understand iterator.

How to Avoid ConcurrentModificationException when using an Iterator

 

Advertisements