一 、list 加法
BigDecimal 类型:
BigDecimal bb =list.stream().map(Plan::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
int、double、long 类型:
double max = list.stream().mapToDouble(User::getHeight).sum();
二、合并list
public static void main(String[] args) throws InterruptedException, ExecutionException {
List<Integer> listA = Arrays.asList(new Integer[]{1, 2});
List<Integer> listB = Arrays.asList(new Integer[]{3, 4});
List<Integer> res = Stream.of(listA, listB).flatMap(Collection::stream).collect(Collectors.toList());
System.out.println(res.size());
res.forEach(System.out::println);
}
三、将list中对象属性取出放到另一个list
list result = list.stream().map(Student:: getName).collect(collectors.tolist());