1、生成List集合
List<Settlement> settlementList = settlementService.queryByReceivableAmountInput(receivableAmountInput);
List<SettlementOutput> outputList = JsonUtil.listToList(settlementList,SettlementOutput.class);
List<String> orderIdList = settlementList.stream().map(o -> o.getOrderId()).collect(Collectors.toList());
2、生成map集合
List<OrderPageVO> orderPageVOS = saleOrderFeignClientService.queryOrderList(orderidList);
Map<String,Integer> map = orderPageVOS.stream().collect(Collectors.toMap(o -> o.getId(), o -> o.getStatus()));
List<SupplierBasetVO> supplierBaseVOByIds = supplierFeignClientService.getSupplierBaseVOByIds(supplierIds);
Map<String, List<SupplierBasetVO>> supplierMap = supplierBaseVOByIds.stream().collect(Collectors.groupingBy(o -> o.getId()));
3、判断
List<BankDirectAccountDownloadMessage> bankDirectAccountDownloadMessageList = new ArrayList<>();
if (!bankDirectAccountDownloadMessageList.stream().filter(item->item.getReceiveSubAccount().equals("111111")).findAny().isPresent()){}
4、返回不可变集合
- Collections.singletonList()返回的是不可变的集合,但是这个长度的集合只有1,可以减少内存空间。但是返回的值依然是Collections的内部实现类,同样没有add的方法,调用add,set方法会报错
List<String> itemIds = Collections.singletonList(orderId);
如何将一个元素优雅的转换成一个集合
List<K> authcChannels = Stream.of(K).collect(Collectors.toList());