Answer» - HASHMAP in Java is a part of the collection class in the java.util package. It is based on Maps and is used for storage of data in Key and Value pairs.
HashMap extends the AbstractMap class and ALSO implements the Cloneable and Serializable interface. - Hashtable in Java was an original part of the java.util package and was implementation of a Dictionary. It was updated by JDK 1.2 and implemented the Map Interface. Currently, it is a part of the collections framework. It also stores data in Key and Value pairs.
Despite of the similarities, HashMap and HashTable have few differences. Let us have a look at them. | Basis | HashMap | Hashtable |
|---|
| Null keys/values | Null key/values are allowed in HashMap. It allows one null key and MULTIPLE null values. | Null key/values are not allowed in Hashtable | | Synchronization | HashMap is not synchronized and is not thread safe. It can’t be shared amongst multiple threads without appropriate synchronization. | Hashtable is synchronized and thread safe. | | Nature of iterator | HashMap iterator is FAIL FAST in nature. | Hashtable iterator is fail safe in nature. | | Introduction | HashMap was introduced in JDK 1.2 | Hashtable is a legacy class. | | Performance | HashMap is fast. | Hashtable is slower than HashMap | | Parent Class | AbstractMap is the parent class for HashMap | Dictionary is the parent class for Hashtable |
|