这篇文章主要介绍了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的重载有哪些”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/4443217/blog/4427317