forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiConsumerEx.java
More file actions
26 lines (20 loc) · 737 Bytes
/
BiConsumerEx.java
File metadata and controls
26 lines (20 loc) · 737 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
package com.zetcode;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
// BiConsumer represents an operation that accepts two input arguments and
// returns no result. This is the two-arity specialization of Consumer.
// Unlike most other functional interfaces, BiConsumer is expected
// to operate via side-effects.
public class BiConsumerEx {
public static void main(String[] args) {
Map<Integer,String> map = new HashMap<>() {{
put(1, "a");
put(2, "b");
put(3, "c");
}};
BiConsumer<Integer,String> biConsumer = (key, value) ->
System.out.printf("%d: %s%n", key, value);
map.forEach(biConsumer);
}
}