Menu
Question Index
...


Write a program to override the smaller length values from source to destination map. Do not copy to destination, if the keys are not present.

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

class OverrideSmallerLengthValuesFromOtherMap2

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

    }


public static void overrideSmallerLengthValues(Map<String, String> destination, Map<String, String> source) {
//Write code here to override the smaller length values from source to destination map
}
}

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