velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jian chen <chenjian1...@gmail.com>
Subject Re: Mutating a collection
Date Wed, 17 Nov 2010 21:35:58 GMT
One thing I think you could do, use a bitset object to record which item is
to be removed. After the loop, loop over the bit set and remove items from
the collection...Just my 3 cents ;-)

Jian

On Wed, Nov 17, 2010 at 1:27 PM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> Jian,
>
> On 11/17/2010 4:19 PM, jian chen wrote:
> > It seems to me that in java, Iterator can not be modified during the
> > iteration loop. It is not particular to Velocity though.
>
>
> http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html#remove()<http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html#remove%28%29>
>
> You may need to update your interview questions ;)
>
> > If you want to remove elements, maybe during the loop, you could mark the
> > indexes for the items to be removed, then, remove them afterwards?
>
> That's an idea, though much less convenient than calling "remove" on an
> iterator.
>
> Thanks,
> -chris
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message