Skip to content

Commit 97e2489

Browse files
committed
BiConsumer Example
1 parent e204c04 commit 97e2489

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.winterbe.java8.samples.lambda;
2+
3+
import java.util.HashMap;
4+
import java.util.function.BiConsumer;
5+
6+
/**
7+
* Created by grijesh
8+
*/
9+
public class Lambda5 {
10+
11+
//Pre-Defined Functional Interfaces
12+
public static void main(String... args) {
13+
14+
//BiConsumer Example
15+
BiConsumer<String,Integer> printKeyAndValue
16+
= (key,value) -> System.out.println(key+"-"+value);
17+
18+
printKeyAndValue.accept("One",1);
19+
printKeyAndValue.accept("Two",2);
20+
21+
System.out.println("##################");
22+
23+
//Java Hash-Map foreach supports BiConsumer
24+
HashMap<String, Integer> dummyValues = new HashMap<>();
25+
dummyValues.put("One", 1);
26+
dummyValues.put("Two", 2);
27+
dummyValues.put("Three", 3);
28+
29+
dummyValues.forEach((key,value) -> System.out.println(key+"-"+value));
30+
31+
}
32+
}

0 commit comments

Comments
 (0)