How to create HashMap In Java

import java.util.HashMap;
import java.util.Map;

public class CreateHashMap {

public static void main(String[] args) {

Map<Integer,String> map = new HashMap<Integer,String>();

* Associates the specified value with the specified key in
this map (optional operation). If the map previously
contained a mapping for the key, the old value is
replaced by the specified value
map.put(2, “amit”);
map.put(5, “yogesh”);

//print hashmap
System.out.println(“HashMap = “+map);




HashMap = {1=ankush, 2=amit, 3=shivam, 4=ankit, 5=yogesh}

Leave a Reply

Your email address will not be published. Required fields are marked *

46 − = 37