Menu
Question Index
...

What will be the output of the following program?

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Test {
    public static void main(String args[]){  
        Map<Integer,String> map = new HashMap<Integer,String>();  
        map.put(1,"Merit");  
        map.put(3,"Java");  
        map.put(2,"Campus");
        map.put(4,"School");
        Set<Map.Entry<Integer,String>> set = map.entrySet();  
        Iterator<Map.Entry<Integer,String>> itr = set.iterator();  
        while(itr.hasNext()){  
            Map.Entry e = itr.next();
            System.out.println(e.getKey()+" "+e.getValue());  
        }  
    }
}


1 Merit
2 Campus
3 Java
4 School
1 Merit
3 Java
2 Campus
4 School
Compilation Error
Runtime Error

Doubts

Problems

Topic: A Generic Class With Two Type Parameters In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App