jdk8 Stream 使用

分片: List<List<Long>> shopIDPartition = ListUtils.partition(dataScopeShopIDList.getShopIDs(), HjdApolloConfig.partitionShopIDSize); 
list转Map:
Map<String, String> itemkeyAndFoodNumMap = setFoodHeadList.stream().collect(Collectors.toMap(OrderFood::getItemKey, s -> s.getFoodNumber().toPlainString() + "@" + s.getUnit()));

Map<String, TblAgentUserMenuRights> menuRightsMap = rightList.stream().collect(Collectors.toMap(r -> r.getMenuCode() + r.getRightCode(), Function.identity()));

Map<String, ShopServiceDeliverRpc.AuthorizedShop> bindPlatformCodeShopMap = authorizedShops.stream()
                    .collect(Collectors.toMap(ShopServiceDeliverRpc.AuthorizedShop::getPlatformCode, a -> a, (v1, v2) -> v1));
                    
Map<Integer, ThirdPlatformAndShopPlatformInfo> shopPlatformInfoMap = thirdPlatformAndShopPlatformInfos.stream()
                .collect(Collectors.toMap(ThirdPlatformAndShopPlatformInfo::getPlatformCode, Function.identity()));
                
Map<Integer, CloudPrinterStatusAndTemplateDto> printerStatusDtoMap = printerStatusResponse.getPrinterList().stream().collect(Collectors.toMap(CloudPrinterStatusAndTemplateDto::getPrinterID, key -> key));
//获取所有的平台 先按时间排序、在通过code排序  string 需要转Long才能比较
List<DcOrderData.PlatformStatusInfo> platformStatusInfoList = platformStatusListList.stream()
        .sorted(Comparator.comparing(DcOrderData.PlatformStatusInfo::getCreateTime, Comparator.comparingLong(Long::parseLong))
                .thenComparingInt(DcOrderData.PlatformStatusInfo::getPlatformCode)).collect(Collectors.toList());
    

List 排序、分组、求和 :
TreeMap<Long, Long> chartShopDateAndNumberMap = chartShopDateAndNumber.stream()
                .sorted(Comparator.comparing(ShopIDAndName::getDateTime).reversed())
                .collect(Collectors.groupingBy(ShopIDAndName::getDateTime, TreeMap::new, Collectors.summingLong(ShopIDAndName::getShopNumDay)));



获取指定字段: List<String> orderKeys = rspOrderLst.stream().map(OrderAttachItem::getOrderKey).collect(Collectors.toList());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值