I try to understand the working of Concurrent modification exception in Java, Initially I tried Concurrent modification exception example with normal ArrayList and HashSet by removing elements while iterating, and then with help of CopyOnWriteArrayList & CopyOnWriteArraySet, I resolved the Concurrent modification exception, Everything works fine. But the problem is, when I implicitly make the set as synchronized with help of Collection.synchronized(set) method, still it throws the Concurrent modification exception. CopyOnWriteArrayList & CopyOnWriteArraySet both are synchronized classes,so it doesnt throw Concurrent modification exception. Collection.synchronized(set) also returns synchronized set, then why it throws the Concurrent modification exception.
Can anyone explain what is issue here?
Here is the sample program,