You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.3 KiB

MapEqual

Instructions

Create a file MapEqual.java.

Write a function areMapEquals that returns true if the maps as parameters are equal. Returns false otherwise.

Expected Functions

import java.util.Map;

public class MapEqual {
    public static boolean areMapEquals(Map<String, Integer> map1, Map<String, Integer> map2) {
        // your code here
    }
}

Usage

Here is a possible ExerciseRunner.java to test your function:

import java.util.Map;

public class ExerciseRunner {
    public static void main(String[] args) {
        Map<String, Integer> map1 = Map.of("Alice", 1, "Bob", 2, "Charly", 3);
        Map<String, Integer> map2 = Map.of("Alice", 1, "Bob", 2, "Charly", 3);
        System.out.println(MapEqual.areMapEquals(map1, map2)); // Expected Output: true

        Map<String, Integer> map3 = Map.of("Alice", 1, "Bob", 2, "Charly", 3);
        Map<String, Integer> map4 = Map.of("Alice", 1, "Bob", 2, "Emily", 3);
        System.out.println(MapEqual.areMapEquals(map3, map4)); // Expected Output: false
    }
}

and its output :

$ javac *.java -d build
$ java -cp build ExerciseRunner
true
false
$

Notions

Map