aspose file tools*
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
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