zoukankan      html  css  js  c++  java
  • Stream常用操作

     
    一 、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());
  • 相关阅读:
    CF-807B
    CF-807A
    sort()的升降序函数操作
    CF-805D
    CF-805B
    CF-805A
    CF-796C
    CF-796B
    图论学习四之Disjoint set union并查集
    图论学习三之Shortest Path最短路
  • 原文地址:https://www.cnblogs.com/liheng2233/p/14631132.html
Copyright © 2011-2022 走看看