Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
import java.util.Map.*;
public class Participate {
    public static void main(String args[]) {
        HashMap participant = new HashMap();
        participant.put(1 + 1, "Samantha");
        participant.put(0 + 1, "Kiran");
        participant.put(2 + 1, "Anushka");
        Set set = participant.entrySet();
        Iterator itr = set.iterator();
        while (itr.hasNext()) {
            Map.Entry m = (Entry) itr.next();
            System.out.print(m.getKey() + " " + m.getValue() + ", ");
        }
        System.out.println();
        itr = set.iterator();
        while (itr.hasNext()) {
            Map.Entry m = (Map.Entry) itr.next();
            System.out.print(m.getKey() + " " + m.getValue() + ", ");
        }
    }
}


2 Samantha, 1 Kiran, 3 Anushka,
1 Kiran, 2 Samantha, 3 Anushka,
2 Samantha, 1 Kiran, 3 Anushka,
2 Samantha, 1 Kiran, 3 Anushka,
1 Kiran, 2 Samantha, 3 Anushka,
1 Kiran, 2 Samantha, 3 Anushka,
Some other output
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