I know there are a lot of similar questions here on SO. But it seems this wasn't discussed before.
In general I want to know, why an Iterator should be used over a For-Each loop, if no element will be removed? So, basically just iterating over a Collection
, and the only used modifier is add
.
I'm aware that Iterator
is the only save option if an element is removed from a Collection
.
Performance is no argument, because the For-Each
will be transformed into an Iterator by the compiler.
The Iterator
is more verbose, so +1 to For-Each
.
Is there any reliable point to use an Iterator over For-Each in the described scenario?