用到的lamda转换

 

对象数组根据某一个属性转换为Map<String,List>

LambdaQueryWrapper<UacCode> queryWrapper = new QueryWrapper<UacCode>().lambda();
queryWrapper.in(UacCode::getCodeType,codeTypes);
List<UacCode> list = codeDao.selectList(queryWrapper);

Map<String, List<UacCode>> codeMap = list.stream().collect(Collectors.groupingBy(UacCode::getCodeType));

数据先筛选,在返回其中一个属性

List<Face> faces = person.getFaces();
           
List<Long> faceIdList = faces.stream().filter(face -> ObjectUtils.isNotEmpty(face.getId())).map(face -> face.getId()).collect(Collectors.toList());

转换为字符串,类似js的join

stringList.stream().collect(Collectors.joining(","))

返回账号id-count对应map

accounts.stream().collect(Collectors.toMap(Account::getId, Account::getUsername));

返回ID-实体对象map

accounts.stream().collect(Collectors.toMap(Account::getId, account -> account));

 

key值重复的处理,以及指定返回map具体实现类 

accounts.stream().collect(Collectors.toMap(Account::getUsername, Function.identity(), (key1, key2) -> key2, LinkedHashMap::new));

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值