Filtering to-many relationship and ConcurrentModificationException

From: Jeff de Vries (jdevrie..frog.com)
Date: Mon Sep 12 2005 - 23:33:09 EDT

  • Next message: Gili: "Re: Filtering to-many relationship and ConcurrentModificationException"

    I'm trying to iterate over a to-many relationship filtering out unwanted objects, something like this:

    Iterator it = getFooArray().iterator();
    while (it.hasNext()) {
       Foo f = (Foo) it.next();
       if some condition on f is true {
          removeFromFooArray(f);
       }
    }
    At runtime, I'm getting a ConcurrentModificationException, which can be raised either in a multithreading situation (which I don't think I'm in), or by "invalidating" the contract of the container (i.e. while in a loop deleting items all of sudden adding an item).

    Does removeFromXXXArray() invalidate any iterators iterating over the list?  Is there a better way to do what I'm trying to do?  Apologies in advance if this is just a dumb Java question.

    Thanks,
    Jeff de Vries



    This archive was generated by hypermail 2.0.0 : Mon Sep 12 2005 - 23:33:15 EDT