James Tharakan wrote:In which class are these defined ?
I mean what does these variable represent
expectedModCount != modCount
foreach loop internally uses Iterator of the collection, so here it is using inner iterator of the PriorityQueue class and that iterator is maintaining these counters.
And when we modify PriorityQueue using poll(), and we are modyfing PriorityQueue with PriorityQueue methods() and looping over it using inner iterator at that time these counter differs, as modCount is shared by both classes, but expectedModCount is only maintained by inner iterator class.
So poll() will increase modCount, but expectedModCount maintained by inner iterator class will remain unchanged, that's the way inner iterator find concurrent modification operation.
Try to see in source code of PriorityQueue.java, it will make everything crystal clear.