Java 8 Functional Interfaces Java Java API
Interface:
java.util.function.BinaryOperator
Method:
static <T> BinaryOperator<T> maxBy(Comparator<? super T> comparator)
Returns a
BinaryOperator
which produces the greater 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 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); } }
Outputthree
|