Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is Fail-Fast collections and Fail-Safe collections in java?

user-image
Question added by Deleted user
Date Posted: 2018/02/07
Kshitij Gupta Gupta
by Kshitij Gupta Gupta , fresher , fresher

Iterators in java are used to iterate over the Collection objects.Fail-Fast iterators immediately throw ConcurrentModificationException if there is structural modification of the collection. Structural modification means adding, removing or updating any element from collection while a thread is iterating over that collection. Iterator on ArrayList, HashMap classes are some examples of fail-fast Iterator.

Fail-Safe iterators don’t throw any exceptions if a collection is structurally modified while iterating over it. This is because, they operate on the clone of the collection, not on the original collection and that’s why they are called fail-safe iterators. Iterator on CopyOnWriteArrayList, ConcurrentHashMap classes are examples of fail-safe Iterator.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.