Write a Java program to create a HashMap to store Key/Value pair


This program creates a HashMap named "stu" that stores key-value pairs, where the keys are of type Integer and the values are of type String. The program then adds 10 key-value pairs to the HashMap using the put() method.

Finally, the program prints the entire HashMap using the println() method, which will output all the key-value pairs in the HashMap

Source Code

import java.util.*;
public class Store_KeyValue
{
	public static void main(String[] args)
	{
		HashMap < Integer, String > stu = new HashMap < > ();
		stu.put(101, "Kim");
		stu.put(102, "Arun");
		stu.put(103, "Deepika");
		stu.put(104, "Ramesh");
		stu.put(105, "Joes");
		stu.put(106, "Abi");
		stu.put(107, "John");
		stu.put(108, "Vijay");
		stu.put(109, "Suga");
		stu.put(110, "Siva");
 
		System.out.println(stu);
	}
}

Output

{101=Kim, 102=Arun, 103=Deepika, 104=Ramesh, 105=Joes, 106=Abi, 107=John, 108=Vijay, 109=Suga, 110=Siva}