java lambda 工作中使用大全

工作中常用的lambda 操作

Lambda表达式将 List<String> 转 List<Long>

        List<String> collect = new ArrayList<>();
        collect.add("123");
        collect.add("456");
        List<Long> userIdList = collect.stream().map(item -> Long.parseLong(item)).collect(Collectors.toList());

lambda表达式将List对象某个字段转换以逗号分隔的String类型

String invoiceNos = receiptDTOList.stream()
        .map(ErpPurchaseInvoiceReceiptDTO::getInvoiceNo).collect(Collectors.joining(","));
表达式将List对象某个字段转换新List
List<ErpPurchaseInvoiceReceiptDTO> receiptDTOList= unionDtos.stream()
        .map(ErpPurchaseInvoiceUnionDTO::getPurchaseInvoiceReceipt).collect(Collectors.toList());

java lambda表达式 将对象某个字段拆分,放入集合,并分组统计

猜你喜欢

转载自blog.csdn.net/qq_27246521/article/details/131458827
今日推荐