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
|
## MapEquals
|
||
1 year ago
|
|
||
|
### Instructions
|
||
|
|
||
1 year ago
|
Create a file `MapEquals.java`.
|
||
1 year ago
|
|
||
1 year ago
|
Write a function `areMapsEqual` that returns `true` if the maps as parameters are equal. Returns `false` otherwise.
|
||
1 year ago
|
|
||
|
### Expected Functions
|
||
|
|
||
|
```java
|
||
|
import java.util.Map;
|
||
|
|
||
1 year ago
|
public class MapEquals {
|
||
|
public static boolean areMapsEqual(Map<String, Integer> map1, Map<String, Integer> map2) {
|
||
1 year ago
|
// 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);
|
||
1 year ago
|
System.out.println(MapEquals.areMapsEqual(map1, map2)); // Expected Output: true
|
||
1 year ago
|
|
||
|
Map<String, Integer> map3 = Map.of("Alice", 1, "Bob", 2, "Charly", 3);
|
||
|
Map<String, Integer> map4 = Map.of("Alice", 1, "Bob", 2, "Emily", 3);
|
||
1 year ago
|
System.out.println(MapEquals.areMapsEqual(map3, map4)); // Expected Output: false
|
||
1 year ago
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
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)
|