1. One-parameter reduce
format
Optional<T> reduce(BinaryOperator<T> accumulator)
T result = a[0]; for (int i = 1; i < n; i++) { result = accumulator.apply(result, a[i]); } return result;
2. Two-parameter reduce
Format
T reduce(T identity, BinaryOperator<T> accumulator)
T result = identity; for (int i = 0; i < n; i++) { result = accumulator.apply(result, a[i]); } return result;
3. Reduce with three parameters, in which the get and set methods are omitted when used.
Format
<U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator,BinaryOperator<U> combiner);
The above is the detailed content of What are the overloads of java Reduce?. For more information, please follow other related articles on the PHP Chinese website!