[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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 20, 2017 01:13:09.