...

/

HashMap: Creation and Insertion

HashMap: Creation and Insertion

Let's look at how to create a HashMap and insert elements into it.

HashMap is a class in the java.utils package that implements the Map interface. It is used to store the key-value pair. Let’s suppose we need to store the stock prices of some companies. In this case, we can use a HashMap. The company name will be the key and the stock price will be the value.

Some of the features of HashMap are:

  1. The keys should be unique.
  2. HashMap allows only one null key.
  3. The values can be null or duplicate.
  4. The keys are stored in random order.

Creating a HashMap

There are four different constructors available to create a HashMap in ...