Types of Maps in Java Programming

 Types of Maps in Java Programming


I/p:

5
vishnu 1
tilak 2
tharun 3
vignesh 4
vinoth 5

O/p:


{tilak=2, vishnu=1, tharun=3, vignesh=4, vinoth=5}
{vishnu=1, tilak=2, tharun=3, vignesh=4, vinoth=5}
{tharun=3, tilak=2, vignesh=4, vinoth=5, vishnu=1}


PROGRAM:

import java.util.*;
public class Map1 {
    
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int iNum=sc.nextInt();
        HashMap<String,Integerhm=new HashMap<>();
        LinkedHashMap<String,Integerlhm=new LinkedHashMap<>();
        TreeMap<String,Integertm=new TreeMap<>();
        for(int i=0;i<iNum;i++)
        {
            String a=sc.next();
            int b=sc.nextInt();
            hm.put(a,b);
            lhm.put(a,b);
            tm.put(a,b);
        }
        System.out.println(hm);
        System.out.println(lhm);
        System.out.println(tm);

    }
}

// I/p:
// 5
// vishnu 1
// tilak 2
// tharun 3
// vignesh 4
// vinoth 5

// O/P:
// {tilak=2, vishnu=1, tharun=3, vignesh=4, vinoth=5}
// {vishnu=1, tilak=2, tharun=3, vignesh=4, vinoth=5}
// {tharun=3, tilak=2, vignesh=4, vinoth=5, vishnu=1}

Comments

Popular posts from this blog

PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION

Program to Copy One Array to Another using Assignment operator

PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY