Java: Best way to iterate through an Collection

Some times there is possibility to get concurrent modification exception while retrieving element from collection.
Example :

On any collection object say Array List , you are adding and removing data sententiously for refesh ui  purpose , then in this case if you are iterating collection object by simple for loop or foreach loop
then there is possibility to get  ConcurrentModificationException

So use iterator to fetch element from collection.

For more details please read internal working of  iterator.

Comments

Popular posts from this blog

Filter In Javafx

Kotlin with StandAlone Complier