public class ReduceTest {
// 计算和
@Test
public void test(){
List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);
Optional<Integer> reduce = integers.stream().reduce((x, y) -> x + y);
System.out.println(reduce.get());
}
//对实体的某个属性的值
@Test
public void test2(){
List<Man> integers = Arrays.asList(
new Man(1,"1",1.0),
new Man(2,"2",2.0),
new Man(3,"3",3.0)
);
Double reduce = integers.stream().map(Man::getAge).reduce(Double::sum).get();
System.out.println(reduce);
}
}
未完待续。。。。