The iterator is failfast. Write a program to demonstrate it by creating two threads that concurrently access

Question:

The iterator is failfast. Write a program to demonstrate it by creating two threads that concurrently access and modify a set. The first thread creates a hash set filled with numbers, and adds a new number to the set every second. The second thread obtains an iterator for the set and traverses the set back and forth through the iterator every second. You will receive a ConcurrentModificationException because the underlying set is being modified in the first thread while the set in the second thread is being traversed.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: