【Lambda】lambda的list用法记录

> 根据实体类的某个字段去重

userList.stream().collect(Collectors.collectingAndThen(
    Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(User::getUsername))), ArrayList::new
));

> list 转 map

Map<Long, String> userMap = userList.stream().collect(
    Collectors.toMap(UserListDto::getId, UserListDto::getName)
);
Map<String, List<OrgImport>> groupByOrgCode = data.stream().collect(
    Collectors.groupingBy(OrgImport::getOrgCode)
);
Map<String, ContractVo> collect = contractList.stream().collect(
    Collectors.toMap(ContractVo::getSymbol, paperContractVo -> ContractVo)
);

> 根据实体类的某个字段求和

BigDecimal total = computeList.stream()
    .map(parcel -> parcel.getNumBbl())
    .reduce(BigDecimal.ZERO, BigDecimal::add);

相关推荐

  1. 【Lambda】lambdalist用法记录

    2023-12-22 16:38:01       63 阅读
  2. hive/spark用法记录

    2023-12-22 16:38:01       57 阅读
  3. socat用法记录

    2023-12-22 16:38:01       30 阅读
  4. 合并两个可能为空List 方法记录

    2023-12-22 16:38:01       32 阅读
  5. SQL中limit用法记录

    2023-12-22 16:38:01       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-22 16:38:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-22 16:38:01       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-22 16:38:01       87 阅读
  4. Python语言-面向对象

    2023-12-22 16:38:01       96 阅读

热门阅读

  1. NPM介绍和常用命令的使用(带示例)

    2023-12-22 16:38:01       58 阅读
  2. Redis vs Memcached 哪一个更适合你的应用程序?

    2023-12-22 16:38:01       53 阅读
  3. vue组件化

    2023-12-22 16:38:01       50 阅读
  4. selenium获取请求和响应

    2023-12-22 16:38:01       63 阅读
  5. ARM 汇编入门

    2023-12-22 16:38:01       53 阅读
  6. adb 基本命令合集

    2023-12-22 16:38:01       56 阅读