Skip to content

Commit

Permalink
Merge pull request winterbe#16 from grijeshsaini/master
Browse files Browse the repository at this point in the history
BiConsumer Example
  • Loading branch information
winterbe committed Nov 20, 2015
2 parents e204c04 + 97e2489 commit 1a59600
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/com/winterbe/java8/samples/lambda/Lambda5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.winterbe.java8.samples.lambda;

import java.util.HashMap;
import java.util.function.BiConsumer;

/**
* Created by grijesh
*/
public class Lambda5 {

//Pre-Defined Functional Interfaces
public static void main(String... args) {

//BiConsumer Example
BiConsumer<String,Integer> printKeyAndValue
= (key,value) -> System.out.println(key+"-"+value);

printKeyAndValue.accept("One",1);
printKeyAndValue.accept("Two",2);

System.out.println("##################");

//Java Hash-Map foreach supports BiConsumer
HashMap<String, Integer> dummyValues = new HashMap<>();
dummyValues.put("One", 1);
dummyValues.put("Two", 2);
dummyValues.put("Three", 3);

dummyValues.forEach((key,value) -> System.out.println(key+"-"+value));

}
}

0 comments on commit 1a59600

Please sign in to comment.