Lambda: BinaryOperator is a BiFunction whose result matches both input types

BinaryOperator<T> specializes BiFunction<T, T, T> for combining two values of the same type into one of that type, the exact shape needed for a manual running-reduction.

Code
BinaryOperator<Integer> max = (a, b) -> a > b ? a : b;
int result = 3;
for (int n : new int[]{7, 2, 9, 4}) {
    result = max.apply(result, n);
}
System.out.println("Max via BinaryOperator: " + result);
Output
Max via BinaryOperator: 9
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms