This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes poll() problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "poll() problem" Watch "poll() problem" New topic
Author

poll() problem

gaurav gupta sitm
Greenhorn

Joined: Jan 12, 2011
Posts: 22


why above program shows bye 2 followed by ConcurrentModificationException
but below program compile fine

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

poll method Retrieves and removes the head of this queue . so when you remove an element from collection at the time of looping you get ConcurrentModificationException. to remove an element while looping use Iterator instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: poll() problem
 
Similar Threads
another question from scjptest.com
PriorityQueue Question
PriorityQueue order?
doubt in John Meyer's mock exam - ConcurrentModificationException!
Modifying PriorityQueue keys while in queue