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:

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only.

Register

50+ Free Java FAQs

50+ Free Big Data FAQs

Already a member? Log in here

300+ Java Interview FAQs

Tutorials on Java & Big Data