-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrentHashMapMethods16.java
More file actions
26 lines (20 loc) · 980 Bytes
/
ConcurrentHashMapMethods16.java
File metadata and controls
26 lines (20 loc) · 980 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
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentHashMapMethods16 {
public static void main(String[] args) throws Exception {
//reduceEntries(long parallelismThreshold, Function<Map.Entry<K,V>,? extends U> transformer, BiFunction<? super U,? super U,? extends U> reducer)
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("one", "1");
map.put("two", "2");
map.put("three", "3");
map.put("four", "4");
System.out.println("Map:" + map);
String result = map.reduceEntries(2, (entry) -> {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
return entry.getKey() + entry.getValue();
}, (v1, v2) -> {
System.out.println("Value1:" + v1 + " Value2:" + v2);
return v1 + v2;
});
System.out.println("Result:" + result);
}
}