Skip to main content

Command Palette

Search for a command to run...

HashMap Example using Java

Published
•1 min read•View as Markdown
H

Working as a Java Developer!

import java.util.HashMap;

public class HashMapExample {

    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("Himanshu", 10);
        map.put("Rupesh", 30);
        map.put("Vedant", 20);

        System.out.println("Size of Map is: "+map.size());
        System.out.println(map);

        if(map.containsKey("Rupesh"))
        {
            Integer a = map.get("Rupesh");
            System.out.println("Value for key Rupesh is: "+a);
        }
    }

}