0

Suppose I am iterating over some collection, then call remove() with absent key so that it does nothing. Will next iteration cause exception?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

4

First of all, the ConcurrentModificationException is optional. A compliant container does not have to attempt to spot concurrent modifications at all.

However, most standard containers tend to do it.

I've just checked a couple of them in JDK7, and they only bump up the modification count once they have found the element.

Having said that, I would discourage you from relying on this behaviour.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • 1
    If you know you're removing an absent key, you deliberately do a no-op. If you don't know, then you deliberately court a `ConcurrentModificationException`. In both cases, you're doing something silly or wrong. – Louis Wasserman Jun 06 '12 at 14:23