HashMap Implementation in Java

HashMap Implementation in Java

In Java, HashMap is a very important and most used concept. It is mostly used in enterprise-level coding for mapping. Also, it is used in e-commerce applications to map orders with customers.

Map is a class of collection in Java which is used to store data in Key & Value pairs. In this tutorial we will learn the implementation of HashMap in Java.

HashMap Program In Java

[java]
import java.util.*;
public class Main{
public static void main(String args[]){
HashMap<Integer,String> map=new HashMap<Integer,String>();
map.put(1,”Ram”);
map.put(2,”Mohan”);
map.put(3,”Sohan”);
map.put(4,”Nitu”);
System.out.println(“HashMap Content”);
for(Map.Entry m : map.entrySet()){
System.out.println(m.getKey()+” “+m.getValue());
}
}
}
[/java]

Output

What is HashMap and its features in details

HashMap is a part of Java’s collection framework that provides the implementation of the Map interface. HashMaps stores the data in key-value pairs. Each key has some value to print the value we fetch values from the key of HashMap and then print it.

HashMap uses a Hashing technique to converting a larger String to a smaller and store it into key-value pair.

Various features of HashMap in Java

  • HashMap is available in the util package of Java.
  • HashMap extends an abstract class AbstractMap.
  • We cannot store duplicate keys in HashMap but we can store duplicate values.
  • HashMap can have only one null key but can have multiple null values.
  • Performance of Java HashMap