Iterator are fail safe while Enumeration is not

Iterator is fail-safe, because it won’t allow you to change the Map while doing iteration.

So basically a fail safe means that it wont allow you to change the map while doing iteration

Hashtable

Hashtable is synchronized, hence its called thread safe meaning multiple threads can access the object concurrently without affecting its data.
It does not allow null keys or values.
Enumeration is not fail-safe. It allows you to change the Hashtable content while traversing.
HashMap

Hashmap is unsynchronized. You need to externally synchronize the hash map object for supporting concurrent programming.
It does allows null keys and values.
Iterator is fail-safe, because it won’t allow you to change the Map while doing iteration.
Allows to safely remove the map entries during iteration.

Advertisements