1.

Difference Between Fail-fast Iterator And Fail-safe Iterator?

Answer»
  • fail-fast iterator THROWS a CONCURRENTMODIFICATIONEXCEPTION if the underlying COLLECTION is structurally modified whereas fail-safe iterator doesn't throw ConcurrentModificationException.
  • fail-fast iterator doesn't CREATE a copy of the collection whereas fail-safe iterator makes a copy of the underlying structure and iteration is done over that snapshot.
  • fail-fast iterator provides operations like REMOVE, add and set (in case of ListIterator) whereas in case of fail-safe iterators element-changing operations on iterators themselves (remove, set and add) are not supported. These methods throw UnsupportedOperationException.



Discussion

No Comment Found