Close

Java 8 Functional Interfaces - BinaryOperator.minBy() Examples

Java 8 Functional Interfaces Java Java API 


Interface:

java.util.function.BinaryOperator

java.util.function.BiFunctionBiFunctionjava.util.function.BinaryOperatorBinaryOperatorLogicBig

Method:

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

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


Examples


package com.logicbig.example.binaryoperator;

import java.util.Comparator;
import java.util.function.BinaryOperator;

public class MinByExample {

public static void main(String... args) {
BinaryOperator<String> maxLengthString = BinaryOperator.minBy(
Comparator.comparingInt(String::length));
String s = maxLengthString.apply("two", "three");
System.out.println(s);
}
}

Output

two




See Also