This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes LinkedList Question 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 "LinkedList Question" Watch "LinkedList Question" New topic

LinkedList Question

Akhil Maharaj
Ranch Hand

Joined: Sep 29, 2007
Posts: 63
Hi ,

Can anybody explain why in the output I am not getting Italy. All I am seeing in the output is hello world.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42030
Because after the second pass through the loop i is 2, while q.size() is 1 since the first two elements have been removed. Modifying a collection that you're iterating through is a dangerous thing to do. If you use an Iterator instead you'll see all elements:

or you can always print the first element in a loop:

Ping & DNS - my free Android networking tools app
GeeCON Prague 2014
subject: LinkedList Question