Sunday, 17 April 2011

Iterators returned by set implementation and concurrent modification

Except EnumSet, the iterators returned by the implemented class's (HashSet/TreeSet) iterator method are fail-fast i.e., if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the Iterator throws a ConcurrentModificationException. But again it is not guaranteed to throw "ConcurrentModificationException" by iterator all the time but will be thrown on best-effort basis. So dont rely on this exception for the correctness of the program.

No comments:

Post a Comment