Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class Example {
    public static void main(String args[]) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("key1", "red");
        map.put("key2", "blue");
        map.put("key3", "green");
        for (String key : map.keySet()) {
            String value = map.get(key);
            System.out.println(value);
        }
    }
}


key1
key2
key3
red
blue
green
key3
key2
key1
green
blue
red
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