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:
- The keys should be unique.
- HashMap allows only one
null
key. - The values can be null or duplicate.
- The keys are stored in random order.
Creating a HashMap
There are four different constructors available to create a HashMap in ...