Wednesday 18 November 2015

What are different ways to iterate over a list

We can iterate over a list in two different ways - using iterator and using for-each loop.

Using iterator is more thread-safe because it makes sure that if underlying list elements are modified, it will throw ConcurrentModificationException.

No comments:

Post a Comment