A fail-fast iterator fails if the data structure has been changed by another thread or a method other than an iterator's method. This is not a guaranteed behaviour as the counter is not synchonized.
A fail-fast iterator create a copy of the data structure, so there can't be any collision. However there is an overhead in creating the clone.
The only practical difference for the developer is that a fail-fast iterator can throw ConcurrentModificationException, whereas a fail-safe iterator cannot throw it.
An example of collection that returns a fail-fast iterator is HashMap.
An example of collection that returns a fail-safe iterator is ConcurrentHashMap.
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.