Menu
Question Index
...

Write a program to find 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] [Ball, Cat, Gun]
[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] [Apple, Ball, Cat, Gun, Ice, Kite, Mat]
[A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat], [A=>Apple, Z=>Ball, K=>Cat, I=>Ink] [Apple, Ball, Cat]
[A=>Apple, C=>Cat, I=>Ice, M=>Mat], [B=>Ball, G=>Gun, K=>Kite, N=>Ice] [Ice]
[A=>Ball, B=>Ant, C=>Gun, G=>Cat, I=>Kite, K=>Ice, M=>Mat], [A=>Gun, B=>Ball, C=>Cat, G=>Gun, I=>Ice, M=>Moon] [Gun, Ball, Cat, Ice]


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
class FindCommonValuesInMaps
{
    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 " + findCommonValues(map1, map2));

    }


    public static Set<String> findCommonValues(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