This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: poll() problem