[Logo]
Forums Register Login
PriorityQueue and Concurrent Modification

Should not the following code give ConcurrentModificationException as we are
using the for-each loop and doing poll() on the PriorityQueue





The output is =============== 2.

Could not understand why this is happening ??
I don't see anything in the API documentation for the iterator() method of PriorityQueue which suggests it might do that.


Agreed. Modifying a collection while iterating is not a good idea because you can get a concurrent modification exception. It doesn't mean that you always will.

Henry

This thread has been viewed 734 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 22, 2018 05:45:16.