Use BiConsumer lambda - Java Lambda Stream

Java examples for Lambda Stream:BiConsumer

Description

Use BiConsumer lambda

Demo Code



import java.util.function.BiConsumer;

public class BiConsumerMain {
  public static void main(String[] args) {
    // We are passing a value to consumer and mention its behabiour
    print((a,b) -> System.out.println(a+" "+b), "Hello","Java");
    print((a,b) -> System.out.println(a+"-"+b), "Hello","Java");
  }//  w w  w  . j  a  v a2 s .c o m

  // Consumer consume value & return nothing
  public static void print(BiConsumer<String, String> biConsumer, String str, String str1) {
    str = str.toUpperCase();
    str1 = str1.toUpperCase();
    //If You accept then behaviour executes,Otherwise not
    biConsumer.accept(str, str1);
  }
}

Related Tutorials