DEV Community

V I N O T H
V I N O T H

Posted on

1 1 1 1 1

HashMap in java

  1. Java HashMap Example

    import java.util.*;
    public class HashMapExample1{
    public static void main(String args[]){
    HashMap map=new HashMap();//Creating HashMap.
    map.put(1,"Mango"); //Put elements in Map.
    map.put(2,"Apple");
    map.put(3,"Banana");
    map.put(4,"Grapes");

2.Idli, Dosai,Pongal with prices

package framework;

import java.util.HashMap; 

public class map {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        HashMap hm = new HashMap();
        hm.put("Idli",20);//entry
        hm.put("Dosai", 30);//entry
        hm.put("Pongal", 50);//entry
        //key--->set
        //Values-->Collection
        System.out.println(hm);
    }

}

Enter fullscreen mode Exit fullscreen mode

output

{Dosai=30, Idli=20, Pongal=50}

Enter fullscreen mode Exit fullscreen mode
  1. Idli,Dosai,Pongal without prices
package framework;

import java.util.HashMap;
import java.util.Set; 

public class map {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        HashMap hm = new HashMap();
        hm.put("Idli",20);//entry
        hm.put("Dosai", 30);//entry
        hm.put("pongal", 50);//entry
        //key--->set
        //Values-->Collection
//      System.out.println(hm);
        Set s = hm.keySet(); 
        System.out.println(s);
    }

}

Enter fullscreen mode Exit fullscreen mode

output

[Dosai, Idli, Pongal]
Enter fullscreen mode Exit fullscreen mode

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

Top comments (0)

Image of Datadog

Keep your GPUs in check

This cheatsheet shows how to use Datadog’s NVIDIA DCGM and Triton integrations to track GPU health, resource usage, and model performance—helping you optimize AI workloads and avoid hardware bottlenecks.

Get the Cheatsheet

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay