Menu
Question Index
...

Write a program to find keys with common values in the given maps.

Input (Map, Map) Output (Set)
[A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat], [A=>Ant, B=>Ball, C=>Cat, G=>Gun, I=>Ink, M=>Moon] [B, C, G]
[A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat], [A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat] [A, B, C, G, I, K, M]
[A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat], [A=>Apple, B=>Box, C=>Cat, I=>Ink] [A, C]
[A=>Apple, C=>Cat, I=>Ice, M=>Mat], [B=>Ball, G=>Gun, K=>Kite, N=>Net] []


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
class FindKeysWithCommonValues
{
    public static void main(String s[])
    {
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("A", "Apple");
        map1.put("B", "Ball");
        map1.put("C", "Cat");
        map1.put("G", "Gun");
        map1.put("I", "Ice");
        map1.put("K", "Kite");
        map1.put("M", "Mat");
        Map<String, String> map2 = new HashMap<String, String>();
        map2.put("A", "Ant");
        map2.put("B", "Ball");
        map2.put("C", "Cat");
        map2.put("G", "Gun");
        map2.put("I", "Ink");
        map2.put("M", "Moon");
        System.out.println("The set of keys with common values are " + findKeysWithCommonValues(map1, map2));

    }


    public static Set<String> findKeysWithCommonValues(Map<String, String> map1, Map<String, String> map2) {
    }

}


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