When doing the project encountered a kind of situation, is to compare two sets of the same elements, after looking for data, found the collections class of the disjoint method
Here's a small example:
1 Importjava.util.Collections;2 ImportJava.util.HashSet;3 ImportJava.util.Set;4 5 Public classDemo {6 7 Public Static voidMain (string[] args) {8Set<string> Set1 =NewHashset<string>();9Set<string> Set2 =NewHashset<string>();Ten OneSet1.add ("1"); ASet1.add ("1111"); -Set1.add ("2222"); -Set2.add ("222"); theSet2.add ("333"); -Set2.add ("111"); - BooleanAAA =Collections.disjoint (Set1, Set2); - System.out.println (AAA); + } - +}
Run Result: true.
Parse: Returns True when there are no identical elements in the two collection. Returns False when there is the same element.
View a method that has no identical elements in two collections. Collections disjoint