java Reduce的重载有哪些
更新:HHH   时间:2023-1-7


这篇文章主要介绍了java Reduce的重载有哪些的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇java Reduce的重载有哪些文章都会有所收获,下面我们一起来看看吧。

1、一个参数的reduce

格式

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、两个参数的reduce

格式

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,其中get和set方法使用时省略。

格式

<U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator,BinaryOperator<U> combiner);
static class ScoreBean {
private String name; //学生姓名
private int score;   //分数,需要汇总该字段   
public ScoreBean(String name, int score) {
this.name = name;
this.score = score;
}
//get 和 set 方法省略
}

关于“java Reduce的重载有哪些”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“java Reduce的重载有哪些”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注天达云行业资讯频道。

返回大数据教程...