stream流求和

List<Vo> list = new ArrayList<>();
for (int i = 0; i < 4; i++) {
Vo vo = new Vo();
vo.setName("21");
vo.setGrade(new Double(2 + i));
list.add(vo);
}
double sum = list.stream().mapToDouble(Vo -> {
Double grade = Vo.getGrade();
return grade;
}).sum();
System.out.println(sum);
上一篇:反射获取对象中的某个属性的值


下一篇:商品详情接口-商品详情VO 2