stream流常用

// 从一个List<object>中获得每个object的对象的id组成一个list:
 List<Long> ids = workStepPos.stream().map(WorkStepPo :: getId).collect(Collectors.toList());
 
// 数组里边有空,去空操作:
 String[] strings = Arrays.stream(materialIds).filter(s -> !"".equals(s)).toArray(String[] ::new);
//根据id获得List中对象:
Cart cart = cartlist.stream().filter(item -> item.getProductId().equals(1L)).findFirst().get()

//list转换为imap
  Map<String, WorkOrderProcessNumberVo> maps = workOrderProcessNumberVos.stream().collect(Collectors.toMap(WorkOrderProcessNumberVo::getProcessName, Function.identity()));

 //去除辅料  num=0的为辅料 再分组计算
      return bomVoList.stream().filter(e -> e.getNum() != 0).collect(Collectors.groupingBy(BomVo :: getInventoryCode, Collectors.summingInt(BomVo :: getNum)));

//选择type为1的对象的id
  List<Long> productProcessIdList=qiProcessRouteNumberList.stream().filter(e->e.getType()==1).map(WorkOrderProcessNumberVo::getProcessId).collect(Collectors.toList());

//过滤对象,修改某些对象值
list.stream() .filter(dog -> dog.getAge()<50)  .forEach(dog -> dog.setAge(26));

//list<object> Object对象包含一个id值,想查看里边的id包含什么
先转换为map形式,id为key
  List<CVenCode> cVenCodeList = labelPrintRecordMapper.getCVenCodeBo(inventoryCodeList);
        Map<String, CVenCode> maps = cVenCodeList.stream().collect(Collectors.toMap(CVenCode::getInventoryCode, Function.identity()));
        for (String inventoryCode : inventoryCodeList) {
            if (!maps.containsKey(inventoryCode)) {
                CVenCode cVenCode = new CVenCode(inventoryCode, "999999");
                cVenCodeList.add(cVenCode);
            }
        }

//字段为空
   List<MaterialVo> result = list.stream().filter(s->StringUtils.isNoneBlank(s.getInventoryType())).filter(materialVo -> !materialVo.getInventoryType().equals("30")).collect(Collectors.toList());


 List<BomPo> bomPoList = bomMapper.selectByExample(example);
            List<ProductingVo> productingVos = bomPoList.stream().map(bomPo -> {
                ProductingVo productingVo = new ProductingVo();
                productingVo.setId(bomPo.getId());
                return productingVo;
            }).collect(Collectors.toList());

List转换为String
  String cVenCode = cVenCodeList.stream().map(c -> c.toString()).collect(Collectors.joining("|"));

List<String>转换为List<Long>:
 List<String> idList = Arrays.asList(strings);
        return idList.stream().map(Long :: valueOf).collect(Collectors.toList());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值