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.
1.5 KiB
1.5 KiB
SetEqual
Instructions
Create a file SetEqual.java
.
Write a function areSetEquals
that returns true
if the sets as parameters are equal. Returns false
otherwise.
Expected Functions
import java.util.Set;
public class SetEqual {
public static boolean areSetEquals(Set<String> set1, Set<String> set2) {
// your code here
}
}
Usage
Here is a possible ExerciseRunner.java to test your function:
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
public class ExerciseRunner {
public static void main(String[] args) {
Set<String> set1 = new TreeSet<>();
set1.add("Alice");
set1.add("Bob");
set1.add("Charly");
Set<String> set2 = new TreeSet<>();
set2.add("Bob");
set2.add("Charly");
set2.add("Alice");
System.out.println(SetEqual.areSetEquals(set1, set2)); // Expected Output: true
Set<String> set3 = new HashSet<>();
set3.add("Alice");
set3.add("Bob");
set3.add("Charly");
Set<String> set4 = new HashSet<>();
set4.add("Alice");
set4.add("Bob");
set4.add("Emily");
System.out.println(SetEqual.areSetEquals(set3, set4)); // Expected Output: false
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
true
false
$