• Post Reply Bookmark Topic Watch Topic
  • New Topic

remove from Iterator  RSS feed

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Which way should I prefer, if I want to remove a Object from an Iterator:


where lays the difference?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you try to remove an element from the collection while you're iterating over it you're going to get an exception fast. So "i.remove()" is the way to go.

If you want to remove all objects you can the collection's "clear" method (or "removeAllElements" or something similar).
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!