Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class States {
    public static void main(String args[]) {
        Map<String, Integer> map = new HashMap<String, Integer>();
        map.put("Andhra", 1);
        map.put("Karnataka", 2);
        map.put("Madhyapradesh", 3);
        Set set = map.entrySet();
        System.out.println(set);
        Iterator it = map.entrySet().iterator();
        System.out.println("Set of mappings are :");
        while (it.hasNext()) {
            Map.Entry me = (Map.Entry) it.next();
            System.out.println(me);
        }
    }
}


{Madhyapradesh=3, Karnataka=2, Andhra=1}
Set of mappings are :
Madhyapradesh=3
Karnataka=2
Andhra=1
[Madhyapradesh=3, Karnataka=2, Andhra=1]
Set of mappings are :
Madhyapradesh=3
Karnataka=2
Andhra=1
{Madhyapradesh=3, Karnataka=2, Andhra=1}
Set of mappings are :
Andhra=1
Karnataka=2
Madhyapradesh=3
[Andhra=1, Karnataka=2, Madhyapradesh=3]
Set of mappings are :
Andhra=1
Karnataka=2
Madhyapradesh=3
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java HashMap Implementation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App