This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedList Question

 
Akhil Maharaj
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic