Java Lambda - BinaryOperator example








BinaryOperator represents an operation upon two operands of the same type, producing a result of the same type.

Method

  1. BinaryOperator minBy
  2. BinaryOperator maxBy

Example

The following example shows how to use BinaryOperator.

import java.util.function.BinaryOperator;

public class Main {
   public static void main(String[] args) {
      BinaryOperator<Integer> adder = (n1, n2) -> n1 + n2;

      System.out.println(adder.apply(3, 4));
   }
}

The code above generates the following result.