04: What is wrong with this code? Java Collection & ConcurrentModificationException

Q9. What is wring with this code?

A9. throws a Runtime exception called “java.util.ConcurrentModificationException” The output will be:

Fix 1: Use iterator.remove() instead of collection.remove

Output:

Fix 2: Use java.util.concurrent classes like CopyOnWriteArrayList

Output:


Java & Big Data Interview FAQs

Java Key Areas Interview Q&As

800+ Java Interview Q&As

Java & Big Data Tutorials

Top