lambda实际使用总结
1: List<map> 中通过几个已知的值,获取未知的值

Map map =  allDefectList.stream().filter(o->  o.get("THEDAY").equals(day) && o.get("DEFECT_TYPE_NEWNAME").equals("defectName")).findFirst().orElse(null);

 

2: java中使用lambda表达式检查list集合是否存在某个值

boolean bool = list.stream().anyMatch(a -> a.getName().equals("a") || a.getNick().equals("a"));

 

3: list 对象求某个字段的和

Integer result = list.stream().collect(Collectors.summingInt(Student::getAge));
System.out.println("所有学生年龄之和 : " + reuslt);

4: list 对象中拼接字符串

 

        List<AqxStorehouseInfos> storehouseInfoList = storehouseInfosMapper.selectBatchIds(param.getStorehouseInfoIds());
        String storehouseStr = storehouseInfoList.stream().map(AqxStorehouseInfos::getStorehouseName).collect(Collectors.joining ("|"));

 

 5: list<Integer> 转化为 String 并以逗号,分隔开

    private List<Integer> storehouseTypeIds;

  String storehouseTypeIds= param.getStorehouseTypeIds().stream().sorted().map(String::valueOf).collect(Collectors.joining (","));

 

 

 

相关文章:

  • 2021-06-24
  • 2022-01-25
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2021-05-04
猜你喜欢
  • 2021-11-09
  • 2021-11-27
  • 2022-12-23
  • 2022-02-05
  • 2022-02-08
相关资源
相似解决方案