mirror of https://github.com/01-edu/public.git
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.
54 lines
1.3 KiB
54 lines
1.3 KiB
1 year ago
|
## 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
|
||
|
|
||
|
```java
|
||
|
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:
|
||
|
|
||
|
```java
|
||
|
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 :
|
||
|
|
||
|
```shell
|
||
|
$ javac *.java -d build
|
||
|
$ java -cp build ExerciseRunner
|
||
|
true
|
||
|
false
|
||
|
$
|
||
|
```
|
||
|
|
||
|
### Notions
|
||
|
|
||
|
[Map](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Map.html)
|