Fail-Fast
1 Fail-fast Iterators fail as soon as they realized that structure of Collection
has been changed since iteration has begun. ( Structural changes means adding,
removing or updating any element from collection while one thread is Iterating
over that collection ).
2 Fail-fast behavior is implemented by keeping a modification count and if
iteration thread realizes the change in modification count it throws
ConcurrentModificationException.
Fail-safe
1 They never fail if you modify the underlying collection on which they are
iterating, because they work on clone of Collection instead of original
collection and that’s why they are called as fail-safe iterator.
2 Iterator of CopyOnWriteArrayList is an example of fail-safe Iterator also
iterator written by ConcurrentHashMap keySet is also fail-safe iterator and
never throw ConcurrentModificationException.