Tuesday, 29 November 2016

Q)What is difference between HashMap and HashTable ?


Ans) Both collections implements Map. Both collections store value as key-value pairs. The key differences between the two are
  1. Hashmap is not synchronized in nature but hashtable is.
  2. Another difference is that iterator in the HashMap is fail-safe while the enumerator 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.

No comments:

Post a Comment