提交 97e24890 编写于 作者: G grijesh

BiConsumer Example

上级 e204c049
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));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册