jdk1.8集合操作新特性

jdk1.8出了很多新特性,对集合操作很多,整理了一下方法,供大家使用

Map map = materialSupplierList.stream().collect(Collectors.toMap(MaterialSupplier::getMaterialCode, supplier -> supplier));



List aggregationItemIdList= resultList.stream().map(PlanAggregationItemListVO::getId).collect(Collectors.toList());

Set materialCodeSet = planItemList.stream().map(PlanItemVO::getMaterialCode).collect(Collectors.toSet()); 


String stationCodes = dataList.stream().map(Station::getStationCode).collect(Collectors.joining(","));
分享一个拼接字符串的方法

// 过滤挂起
List statusList = new ArrayList<>();
List suspended = statusList.stream().filter(status -> status == StockTransferOrderStatus.SUSPENDED).collect(Collectors.toList()); 

//分组
Map> groupMap = batchItemListFiler.stream().collect(Collectors.groupingBy(ShippingBatchItem::getShippingBatchId));

//数量累加求和
Long shouldCountSum = asnItems.stream().map(OutBoundShippingNoticeItemPo::getCurrQuantity).reduce(Long::sum).get();

List receiptRecordPos = new ArrayList<>();
goodsReciptEventList.stream().forEach(item -> receiptRecordPos.add(ReceiptRecordPo.build(userName, item, objectMapper)));


//MAP
Map receiptItemPoMap = receiptItemList.stream().collect(Collectors.toMap(ReceiptItemPo::getId, item -> item)); 
Map map = esList.stream().collect(Collectors.toMap(UnifiedInventoryEs::getUnifiedInventoryId, Function.identity()));

//集合快速过滤设值
list.stream().forEach(item-> {
item.setEnabledName(item.getEnabled() ? "启用":"禁用");
});


//按照集合里的参数 拼接成目标集合
List improtSnList = list.stream().map(d ->d.getMaterialCode()+"_"+d.getMaterialSn()).collect(Collectors.toList());

//通过条件过滤其中数据,再拼装成集合
List changePnList = rmaReturnDetailSnList.stream().filter(iteam ->NoRmaReasonDetailTypeEnum.MIX.getType().equals(iteam.getNoRmaReasonDetailType()) && !iteam.getMaterialCode().equals(iteam.getMixMaterialCode())).collect(Collectors.toList());
//将集合转成另外一种对象集合
List repairOrderSnTempList = changePnList.stream().map(RmaReturnDetailSn::buildUpdateMaterialCodeBySn).collect(Collectors.toList());

你可能感兴趣的:(Java,基础)