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.
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);
Max via BinaryOperator: 9
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