您的位置:首页 >java Reduce的重载有哪些
发布于2023-04-30 阅读(0)
扫一扫,手机访问
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 方法省略
}
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
9