Menu
Question Index
...

Write a program to compare two given maps.Use one of the Map interface methods.

Input (Map, Map) Output (Boolean)
{A=1, B=2, C=3, D=4, E=5}, {A=1, B=2, C=3, D=4, E=5} true
{P=12, Q=-20, R=36, S=22, T=96, X=2, Y=5}, {Q=-20, R=36, P=12, Y=5, T=96, X=2, S=22} true
{Lion=1, Tiger=2, Cat=3, Rabbit=4, Mouse=5, Donkey=6}, {Lion=1, Tiger=2, Cat=3, Rain=4, Mouse=5, Donkey=6} false
null, {Book=-1, Pen=2, Pencil=-3, Scale=4} null


import java.util.*;
class CampareTwoMaps
{
    public static void main(String s[])
    {
        Map<String, Integer> firstInput = new LinkedHashMap<String, Integer>();
        firstInput.put("A", 1);
        firstInput.put("E", 5);
        firstInput.put("B", 2);
        firstInput.put("C", 3);
        firstInput.put("D", 4);
        Map<String, Integer> secondInput = new LinkedHashMap<String, Integer>();
        secondInput.put("A", 1);
        secondInput.put("E", 5);
        secondInput.put("B", 2);
        secondInput.put("C", 3);
        secondInput.put("D", 4);
        System.out.println("Both maps are same : " + areSame(firstInput, secondInput));

    }


    public static Boolean areSame(Map<String, Integer> firstInput, Map<String, Integer> secondInput) {
    }

}

Doubts

Problems

Topic: LinkedHashMap In Java with Code Example

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App