Easy learning with example program codes

what is the difference between hashmap and hashtable in java?


HashMap extends AbstractMap class and implements the Map interface. It contains the elements in key-value pair form. It not maintains any order for its elements. It not allowed duplicate key. A HashMap can have only one null key and multiple null values.



Hashtable extends Dictionary class and implements Map interface. It contains elements in key-value pair. It not allowed duplicate key. It is synchronized. It can’t contain null key or value. It uses hashcode() method for finding the position of the elements.


HashMap Hashtable
It is not synchronized. It is synchronized.
It can contain one null key and multiple null values. It cannot contain any null key or null value.


Java interview questions on collections

Sign Up/ Sign In
Ask a Question

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki