jdk8的stream新特性写法

1、集合A判断是否包含集合B里面的元素,并且把包含元素放到一个新集合里面

List<TagBean> tagBean = tagBeans.stream().filter(adminMo.getTagList()::contains).collect(toList());

2、把subListByChildId里面的subId作为key,本身对象ChannelSubMo作为value

List<ChannelSubMo> subListByChildId;
Map<String, ChannelSubMo> subMoMap =  subListByChildId.stream().collect(Collectors.toMap(ChannelSubMo::getSubId, channelSubMo -> channelSubMo));

3、把集合里面对象的某个字段转成List

List<String> ageList = list.stream().map(Person::getAge).collect(Collectors.toList());

4、根据集合对象里面的某个字段分组

List<SvOrderInputVo> excelVos;
Map<Integer,List<SvOrderInputVo>>  map = excelVos.stream().collect(Collectors.groupingBy(SvOrderInputVo::getSvOrderThirdStatus));

5、根据map里面的key获取value值,把value值去重并放到一个新的集合里面

Map<Integer,List<SvOrderInputVo>>  map;
List<String> svOrderIdList = map.get(svOrderThirdStatus).stream().map(SvOrderInputVo::getSvOrderId).distinct().collect(Collectors.toList());

6、key是分配客户的数量(根据thisWeekNum分组),value是分配客户数量的顾问id集合(需要去重)

List<DacMatchAgentWeightMo> totalList;
Map<Integer, Long> weekMap = totalList.stream().filter(mo -> saleArea.equals(mo.getSaleArea()))
                        .collect(Collectors.groupingBy(DacMatchAgentWeightMo::getThisWeekNum, Collectors.mapping(DacMatchAgentWeightMo::getAgentId, Collectors.toList())));

7、判断map里面key>0的数据并把value加和

Map<Integer, List<String>> map;
List<String> alreadyMatchList = map.entrySet().stream().filter(entry -> entry.getKey() > 0).flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList());

8、循环map里面的key,把key和value(也就是list.size)相乘,然后把所有的值sum起来

Map<Integer, List<String>> map;
int totalWeekNum = map.entrySet().stream().mapToInt(entry -> entry.getKey() * entry.getValue().size()).sum();

9、低于某个值的数据加和

Map<Integer, Long> weekMap;
long lessAverageNumWeek = weekMap.values().stream().filter(value -> value < 3).mapToLong(value -> value).sum();
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值