Re: what happen in for (x:List) and iterator when adding to List
- From: Andreas Leitgeb <avl@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 25 Sep 2008 13:54:49 GMT
Lew <noone@xxxxxxxxxxxxx> wrote:
for (ListIterator<E> it = list.listIterator(); it.hasNext(); )Where does 'x' come from?
{....; list.add(x);
}
Probably it doesn't matter at all. It's just some element that's
to be added to end of the currently iterated list.
It doesn't work that way, of course. I understood the question not
so much as about the "why", but rather about "how else can I achieve
such an effect".
for (x:list){Wouldn't that make the List grow until it hits OutOfMemoryError (OOME)?
.....; list.add(x);
}
(Isn't that the point of Andreas' response?)
No that wasn't it. I (boldly) assumed, that the ".....;" contained
something like: "if (x.exhausted()) continue; x.exhaustGradually();" :-)
Anyway, I meanwhile noticed, that my code is broken as well, because
I re-iterate also those elements that were originally in list...
.
- References:
- Prev by Date: Re: what happen in for (x:List) and iterator when adding to List
- Next by Date: Re: what happen in for (x:List) and iterator when adding to List
- Previous by thread: Re: what happen in for (x:List) and iterator when adding to List
- Next by thread: Re: what happen in for (x:List) and iterator when adding to List
- Index(es):
Relevant Pages
|