Menu
Question Index
...

Write a program to identify those keys which are present only in the first map.

Input (Map, Map) Output (Set)
[A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat], [B=>Ball, C=>Cat, I=>Ink, M=>Moon] [A, G, K]
[A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat], [A=>Ant, B=>Box, C=>Cat, G=>Girl, I=>Ink] [K, M]
[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=>Apple, B=>Ball, C=>Cat], [G=>Gun, I=>Ice, K=>Kite, M=>Mat] [A, B, C]
[B=>Ball, G=>Gun, K=>Kite], [A=>Apple, B=>Ball, C=>Cat, G=>Gun, I=>Ice, K=>Kite, M=>Mat] []


import java.util.*;
class IdentifyFirstMapOnlyKeys
{
    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("B", "Ball");
        map2.put("C", "Cat");
        map2.put("I", "Ink");
        map2.put("M", "Moon");
        System.out.println("The set of keys which are present only in the first map are " + findKeysPresentOnlyInFirstMap(map1, map2));

    }


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