Java8 Stream流对List集合的求和操作:
1、dobule
Double sum = list.stream().reduce(0.0, (a, b) -> a + b);
Double sum = list.stream().reduce(0.0, Double::sum);
2、int
int sum = list.stream().collect(Collectors.summingInt(Integer::intValue));
int sum = list.stream().mapToInt(Integer::intValue).sum();
3、BigDecimal
BigDecimal sum = list.stream().reduce(BigDecimal.ZERO,BigDecimal::add);
// 过滤 null
BigDecimal sum = list.stream().filter(f-> f !=null).reduce(BigDecimal.ZERO,BigDecimal::add);
4、统计过滤后条数
// 集合不等于'1'的条数
long count = list.stream().filter(f -> !f.equals("1")).count();