-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConcurrentHashMapMethods3.java
45 lines (31 loc) · 1.16 KB
/
ConcurrentHashMapMethods3.java
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
42
43
44
45
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentHashMapMethods3 {
public static void main(String[] args) throws Exception {
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
Set<String> set = map.keySet("1");
set.add("one");
set = map.keySet("2");
set.add("two");
set = map.keySet("3");
set.add("three");
set = map.keySet("4");
set.add("four");
System.out.println("Set:" + set);
System.out.println("Map:" + map);
ConcurrentHashMap<String, String> map2 = new ConcurrentHashMap<>();
map2.put("one", "1");
map2.put("two", "2");
map2.put("three", "3");
map2.put("four", "4");
Set<String> set2 = map2.keySet();
System.out.println("Set2:" + set2);
Set<String> set3 =new HashSet<>();
set3.add("five");
set3.add("six");
set.addAll(set3);
System.out.println("Set:" + set);
System.out.println("Map:" + map);
}
}