Skip to content

Commit d581c26

Browse files
Add files via upload
1 parent df72c1b commit d581c26

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

ConcurrentHashMapMethods16.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.concurrent.ConcurrentHashMap;
2+
3+
public class ConcurrentHashMapMethods16 {
4+
5+
public static void main(String[] args) throws Exception {
6+
//reduceEntries​(long parallelismThreshold, Function<Map.Entry<K,​V>,​? extends U> transformer, BiFunction<? super U,​? super U,​? extends U> reducer)
7+
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
8+
map.put("one", "1");
9+
map.put("two", "2");
10+
map.put("three", "3");
11+
map.put("four", "4");
12+
System.out.println("Map:" + map);
13+
14+
String result = map.reduceEntries(2, (entry) -> {
15+
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
16+
return entry.getKey() + entry.getValue();
17+
}, (v1, v2) -> {
18+
System.out.println("Value1:" + v1 + " Value2:" + v2);
19+
return v1 + v2;
20+
});
21+
System.out.println("Result:" + result);
22+
}
23+
}
24+
25+
26+

0 commit comments

Comments
 (0)