What are the differences between HashMap and Hashtable in Java?

Can someone please explain the difference between a HashMap and a Hashtable in Java? Please also let me know which is more efficient for java applications which doesn't have multi-threading applied.


  • HashMap is not synchronized.

    1. Good for non-threaded applications.
    2. Performance is better.
    3. Allows one null key and any number of null values

    Hashtable is synchronized.

    1. Good for threaded applications.
    2. Null keys or values are not allowed
  • The HashMap class extends AbstractMap and implements the Map interface. It does not add any methods on its own. Hashtable implements a hash table. It stores key/value pairs in a hash table i.e. keys are mapped to values. Key and value can be any non-null object. For more details and for practice programs please follow the link http://java.meritcampus.com/t/182/Hashmap http://java.meritcampus.com/t/221/Hashtable

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!