Hashtable Vs HashMap in Java

Wikitechy | 3964 Views | java | 13 Jun 2016



  • A Hashtable is an array of list, where each list is called as bucket.
  • The position of bucket is identified by calling the hashcode () method.
  • A Hashtable contains values based on the key. 

1. Hash table contains only unique elements.

2. It may not have any null key or value.

Hash Map:

  • The HashMap & HashTable both are similar
  • HashMap contains values based on the key.
  • HashMap implements on Map interface & extends AbstractMap class.

1. It contains only unique elements.

2. It may have one null key and multiple null values.

3. It maintains no order.

Similarities between Hashtable and HashMap in Java

  • Both Hashtable and HashMap implements java.util.Map interface library.
  • Hashtable and HashMap both are hash based collection and works on the principle of hashing.
  • Both Hashtable and HashMap provides constant time performance for put and get method and the objects are distributed uniformly across the bucket. From JDK 4 both Hashtable and HashMap are part of Java collection framework. 

Difference between Hashtable and HashMap in Java

  • HashMap is not thread-safe while Hashtable is a thread-safe collection.
  • HashMap will not synchronized but it performs better than Hashtable.
  • The third difference on Hashtable vs HashMap is that Hashtable is obsolete class and we should be using ConcurrentHashMap in the place of Hashtable in Java.

Applies to:

  • J2SE 1.3
  • J2SE 1.4
  • J2SE 5.0
  • Java SE 6
  • Java SE 7
  • Java SE 8

Related Tags:

  • Difference between Hashtable and HashMap in Java
  • Difference between HashMap and Hashtable
  • What is difference between HashMap and Hashtable in Java?
  • java - Differences between HashMap and Hashtable? 
  • What are the differences between HashMap and Hashtable?
  • What is the difference between Hashtable and HashMap?
  • diff b/w hashmap and hashtable
  • difference b/w hashmap and hashtable
  • differences b/w hashtable vs hashmap
  • why hashmap is faster than hash table
  • advantage of hashmap over hashtable


Bug Bounty

Join our Community