RSS Feed for This PostCurrent Article

Java – HashMap versus Hashtable

This is one of the basic questions that is often asked by novice programmers.

In summary, both are more or less the same, except

  • Access to the Hashtable is synchronized while access to the HashMap is not.
  • Iterator in the HashMap is fail-safe while the enumerator for the Hashtable is not.
  • HashMap permits null values in it, while Hashtable does not.

Hashtable extends Dictionary and implements Map.

public class Hashtable<K,V>
    extends Dictionary<K,V>
    implements Map<K,V>, Cloneable, {

HashMap extends AbstractMap and implements Map.

public class HashMap<K,V>
    extends AbstractMap<K,V>
    implements Map<K,V>, Cloneable, Serializable

Since both implement Map interface. You can do the followings…

Map h = new Hashtable();
Map m = new HashMap();

Trackback URL

Sorry, comments for this entry are closed at this time.