CodesJava

Easy learning with example program codes

what is the difference between hashmap and hashtable in java?

HashMap:

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:

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.

 

HashMapHashtable
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

Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status