Java Stream How to - Call BinaryOperator with Lambda








Question

We would like to know how to call BinaryOperator with Lambda.

Answer

//  w  ww.  j  av a  2  s. c o m
import java.util.function.BinaryOperator;

public class Main {

  public static void main(String[] args) {
    BinaryOperator<String> bi = (s1, s2) -> s1 + s2;

    String result = bi.apply("Just ", "Java 8");
    System.out.println(">" + result);
  }

}

The code above generates the following result.