Important Features of HashMap

To access a value one must know its key. HashMap is known as HashMap because it uses a technique called Hashing. Hashing is a technique of converting a large String to a small String that represents the same String. A shorter value helps in indexing and faster searches. HashSet also uses HashMap internally.
A few important features of HashMap are: 

  • HashMap is a part of java.util package.
  • HashMap extends an abstract class AbstractMap which also provides an incomplete implementation of the Map interface.
  • It also implements a Cloneable and Serializable interfaces. K and V in the above definition represent Key and Value respectively.
  • HashMap doesn’t allow duplicate keys but allows duplicate values. That means A single key can’t contain more than 1 value but more than 1 key can contain a single value.
  • HashMap allows a null key also but only once and multiple null values.
  • This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time. It is roughly similar to HashTable but is unsynchronized.

HashMap in Java

In Java, HashMap is a part of Java’s collection since Java 1.2. This class is found in java.util package. It provides the basic implementation of the Map interface of Java. HashMap in Java stores the data in (Key, Value) pairs, and you can access them by an index of another type (e.g. an Integer). One object is used as a key (index) to another object (value). If you try to insert the duplicate key in HashMap, it will replace the element of the corresponding key. 

Similar Reads

What is HashMap?

Java HashMap is similar to HashTable, but it is unsynchronized. It allows to store the null keys as well, but there should be only one null key object and there can be any number of null values. This class makes no guarantees as to the order of the map. To use this class and its methods, you need to import java.util.HashMap package or its superclass....

Java HashMap Examples

Below is the implementation of an example of Java HashMap:...

HashMap Declaration

...

Hierarchy of Java HashMap

public class HashMap extends AbstractMap implements Map, Cloneable, Serializable...

Creating HashMap in Java

...

Java HashMap Constructors

Let us understand how we can create HashMap in Java with an example mentioned below:...

Performing Various Operations on HashMap

...

Complexity of HashMap in Java

HashMap provides 4 constructors and the access modifier of each is public which are listed as follows:...

Important Features of HashMap

...

Internal Structure of HashMap

...

Performance of HashMap

...

Synchronized HashMap

...

Methods in HashMapassociate

1. Adding Elements in HashMap in Java...

Advantages of Java HashMap

...

Disadvantages of Java HashMap

...

Also, Read

...

FAQs on Java HashMap

...