This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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.
 
 
subject: poll() problem