forked from yangyiRunning/DataStructureAlgorithmsJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnion.java
More file actions
41 lines (33 loc) · 843 Bytes
/
Union.java
File metadata and controls
41 lines (33 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package ds;
import java.util.HashSet;
import java.util.Set;
/**
* A = A∪B
*
* @author yangyi 2018年05月04日18:15:39
*/
public class Union {
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public static void main(String[] args) {
Set<String> a = new HashSet<>();
a.add("张三");
a.add("李四");
a.add("王五");
Set<String> b = new HashSet<>();
b.add("赵六");
b.add("张三");
b.add("李四");
System.out.println("before");
System.out.println("a:" + a.toString());
for (String s : b) {
if (!a.contains(s)) {
a.add(s);
}
}
System.out.println("after");
System.out.println("a:" + a.toString());
}
}