Iterators.filter and remove
Kevin Bourrillion
kevinb at google.com
Tue May 22 07:25:29 PDT 2012
On Tue, May 22, 2012 at 4:36 AM, David Conrad <drconrad at gmail.com> wrote:
It is not possible to remove an element from a collection while iterating
> with the iterator from java.util.Iterators.filter().
>
The problem is that remove can only *sometimes* work. If you've called
hasNext() after next() (for example because you're trying to remove the
final element), it can't possibly function as expected. In Guava, we also
preferred a remove that consistently is left unimplemented over one that
might hide latent bugs. This also preserves the fact that hasNext() in no
way changes the observable state of the iterator, which is a good thing.
--
Kevin Bourrillion @ Google
Java Core Libraries Team
http://guava-libraries.googlecode.com
More information about the lambda-dev
mailing list