-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConcurrentHashMapMethods15.java
35 lines (26 loc) · 1.15 KB
/
ConcurrentHashMapMethods15.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
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentHashMapMethods15 {
public static void main(String[] args) throws Exception {
//reduceEntries(long parallelismThreshold, BiFunction<Map.Entry<K,V>,Map.Entry<K,V>,? extends Map.Entry<K,V>> reducer)
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("one", "1");
map.put("two", "2");
map.put("three", "3");
map.put("four", "4");
map.put("five", "5");
map.put("six", "6");
map.put("seven", "7");
System.out.println("Map:" + map);
System.out.println(" ");
map.reduceEntries(2, (entry1, entry2) -> {
System.out.println("Entry1:" + entry1 + " Entry2:" + entry2);
return entry1;
});
System.out.println(" ");
String result = map.reduceEntries(2, (entry1, entry2) -> {
System.out.println("Entry1:" + entry1 + " Entry2:" + entry2);
return entry1;
}).toString();
System.out.println("Result:" + result);//Result hold the sendcond last entry
}
}