HashMap and HashTable differ based on the following parameters:

  • Nature

           HashMap is not synchronized in nature.

           HashTable is synchronized in nature

  • Traversed by
           HashMap can be traversed by using an iterator
           HashTable can be traversed by using an iterator or enumerator

  • Null value/key
          HashMap allows only one null key and any number of null values.
          HashTable doesn’t allow key or value as null.

  • fail-fast nature of iterator
          Iterator in HashMap is fail-fast.
          Enumerator in HashTable is not fail-fast.

  • Performance
          HashMap is faster performance wise.
          HashTable is slower in comparision to HashMap performance wise.
          Reason: Since HashTable is synchronized in nature so it doesn’t allow multi-threading                                       operation on a particular resource at a time thus turning out to be slower than                                       HashMap which is non-synchronized by nature.

You may also like to read:

  • ArrayList vs LinkedList
  • ArrayList vs Vector
  • Collection vs Collections
  • ArrayList vs HashSet
  • Iterator vs Enumeration

Source link

Difference: HashMap vs HashTable

Leave a Reply

Your email address will not be published. Required fields are marked *