S
Swarat Chaudhuri
Hi everyone,
I am encountering concurrent modification exceptions while using the
class "Iterator" to iterate over a Java "HashSet". I kind of know *why*
I am getting them, but cannot quite figure out a strategy that would let
me avoid them. And assistance from experienced people always being
wonderful...
I have a set S over which I would like to iterate. While iterating, in
certain cases, I want to add elements to the set. I would like the
iterator to treat these new elements as if they have not been seen so
far. However, doing so seems to guarantee that concurrent modification
exception will be thrown.
So the question is, is there a way to achieve what I want to do? Without
needing to restart the iteration every time an "update" occurs?
I am willing to use a list instead of a set. But, for efficiency
reasons, I also want fast membership queries. So my second question:
does anyone know of an implementation of the List interface with a
"contains" method of sublinear complexity?
Thanks in advance,
Swarat
I am encountering concurrent modification exceptions while using the
class "Iterator" to iterate over a Java "HashSet". I kind of know *why*
I am getting them, but cannot quite figure out a strategy that would let
me avoid them. And assistance from experienced people always being
wonderful...
I have a set S over which I would like to iterate. While iterating, in
certain cases, I want to add elements to the set. I would like the
iterator to treat these new elements as if they have not been seen so
far. However, doing so seems to guarantee that concurrent modification
exception will be thrown.
So the question is, is there a way to achieve what I want to do? Without
needing to restart the iteration every time an "update" occurs?
I am willing to use a list instead of a set. But, for efficiency
reasons, I also want fast membership queries. So my second question:
does anyone know of an implementation of the List interface with a
"contains" method of sublinear complexity?
Thanks in advance,
Swarat