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

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Jetbrains Survey

Calling all developers!

Participate in the Developer Ecosystem Survey 2025 and get the chance to win a MacBook Pro, an iPhone 16, or other exciting prizes. Contribute to our research on the development landscape.

Take the survey

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay