1.BigDecimal求和 BigDecimal winBidTotalPrice = notBargainList.stream().map(BidSupplierProjectItem::getDealTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); 2.Integer 最大值 Integer max = caseManagerCompRelationships.stream().map(CaseManagerCompRelationship::getId).max(Comparator.comparing(x -> x)).orElse(0); 3.String合并 String str = bidSubFileList.stream().map(BidSubFile::getFileName).reduce("", String::concat); 逗号隔开 String s = list.stream().map(BidSubFile::getFileName).collect(Collectors.joining(",")); 4.集合 List<Long> l = list.stream().map(BidSubFile::getId).collect(Collectors.toList()); List<String> l = list.stream().map(BidSubFile::getId).map(Long -> Long + "").collect(Collectors.toList()); 5.数组 Long[] l = list.stream().map(BidSubFile::getId).toArray(Long[]::new); 6.转Map ---Map<String,TestCase> testCaseMap = testCaseList.stream().collect(Collectors.toMap(key -> key.getId(),value -> value)); ---Map<String, Dto> collect = result.getResult().stream().collect(Collectors.toMap(Dto::getTableName, value -> value));
Lamdba表达式
于 2022-04-11 14:32:02 首次发布