Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class MapExample {
    public static void main(String args[]) {
        Map map = new HashMap();
        map.put("key1", "family");
        map.put("key2", "relatives");
        map.put("key3", "friends");
        System.out.println(map);
        String str = (String) map.get("key1");
        System.out.print(str);
    }
}


{key3=friends, key2=relatives, key1=family}
family
{key1=family, key2=relatives, key3=friends]
family
{key3=friends, key2=relatives, key1=family}
[EMPTY]
{key1=family, key2=relatives, key3=friends]
[EMPTY]
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