BinaryOperator minBy example

Description

BinaryOperator minBy method returns a BinaryOperator which returns the lesser of two elements according to the specified Comparator.

Syntax

minBy has the following syntax.


static <T> BinaryOperator<T> minBy(Comparator<? super T> comparator)

Example

The following example shows how to use minBy.


import java.util.Comparator;
import java.util.function.BinaryOperator;
//from  w w w  .  j  a  v  a 2s .c o m

public class Main {
   public static void main(String[] args) {
     BinaryOperator<Integer> bi = BinaryOperator.minBy(Comparator.reverseOrder());
     System.out.println(bi.apply(2, 3));
   }
}

The code above generates the following result.