Example & Tutorial understanding programming in easy ways.

What is difference between HashMap and HashTable?

What is difference between HashMap and HashTable?

This is most common interview question. This question asked by almost interviewer. There are mainly three points interviewers want from candidates. Both store value as key-value pairs.
The key differences between the two are

1. Hashmap is not synchronized in nature but Hashtable is synchronised.
2. iterator in the HashMap is fail-safe while for the Hashtable isn't.
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.

Read More →