Menu
Question Index
...


Write a program to copy details from one hash map to another, only if the first map does not have that value.

Input (HashMap, HashMap) Output (HashMap)
{key4=>"Hello", key3=>"are", key7=>"."}, {key5=>"how", key6=>"are", key2=>"you"} {key4=>"Hello", key3=>"are", key7=>".", key5=>"how", key2=>"you"}
{key4=>"Do", key3=>"not", key6=>"stupid", key2=>"me"}, {key1=>"play", key8=>"with", key7=>"not", key9=>"it"} {key4=>"Do", key3=>"not", key6=>"stupid", key2=>"me", key1=>"play", key8=>"with", key9=>"it"}
{key4=>"Do", key3=>"so", key6=>"open", key2=>"brains", key2=>"Your", key1=>"fall"}, {key8=>"not", key7=>"be", key9=>"out", key19=>"minded", key29=>"brains"} {key4=>"Do", key3=>"so", key6=>"open", key2=>"brains", key2=>"Your", key1=>"fall", key8=>"not", key7=>"be", key9=>"out", key19=>"minded"}
{key10=>"Fun", key3=>"there", key6=>"fair", key2=>"set"}, {key1=>"up", key8=>"there", key7=>".", key9=>"up"} {key10=>"Fun", key3=>"there", key6=>"fair", key2=>"set", key1=>"up", key7=>"."}

class CopyMapIfValueDoesNotExist

{    public static void main(String s[])
    {
        Map inputMap1 = new HashMap();
        inputMap1.put("key11", "Hai");
        inputMap1.put("key12", "how");
        inputMap1.put("key13", "you");
        inputMap1.put("key14", ".");
        Map inputMap2 = new HashMap();
        inputMap2.put("key21", "are");
        inputMap2.put("key22", "how");
        inputMap2.put("key23", "friend");
        inputMap2.put("key24", ".");
        inputMap2.put("key25", "Hello");
        System.out.println("The resultant map is : " + copyMap(inputMap1, inputMap2));

    }


public static Map<String, String> copyMap(Map<String, String> inputMap1, Map<String, String> inputMap2) {
//Write code here to copy details from one hash map to another, only if the first map does not have that value
}
}

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