Java 8 Functional Interfaces Java Java API
java.util.function.BinaryOperator
static <T> BinaryOperator<T> maxBy(Comparator<? super T> comparator)
Returns a BinaryOperator which produces the greater of two elements according to the specified Comparator.
BinaryOperator
Comparator
package com.logicbig.example.binaryoperator;import java.util.Comparator;import java.util.function.BinaryOperator;public class MaxByExample { public static void main(String... args) { BinaryOperator<String> maxLengthString = BinaryOperator.maxBy( Comparator.comparingInt(String::length)); String s = maxLengthString.apply("two", "three"); System.out.println(s); }}
three