What is difference between HashMap and HashTable?

Both collections implements Map. Both collections store value as key-value pairs. The key differences between the two are
1. Access to the Hashtable is synchronized on the table while access to the HashMap isn't. You can add it, but it isn't there by default.
2. Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating, you'll know. • Fail-safe - “if the Hashtable is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationException”
3. HashMap permits null values and only one null key, while Hashtable doesn't allow key or value as null.

No comments:

Post a Comment

Please Provide your feedback here