Home > Java > javaTutorial > What are the overloads of java Reduce?

What are the overloads of java Reduce?

WBOY
Release: 2023-05-06 11:55:06
forward
1394 people have browsed it

1. One-parameter reduce

format

Optional<T> reduce(BinaryOperator<T> accumulator)
Copy after login
T result = a[0];  
for (int i = 1; i < n; i++) {
result = accumulator.apply(result, a[i]);  
}
return result;
Copy after login

2. Two-parameter reduce

Format

T reduce(T identity, BinaryOperator<T> accumulator)
Copy after login
T result = identity;
for (int i = 0; i < n; i++) {
result = accumulator.apply(result, a[i]);  
}
return result;
Copy after login

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);
Copy after login
rrree

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template