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

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay