JDK1.8新属性lambda

List<ProductInfo> productInfoList = productService.findUpAll();
//精简方法(java8, lambda)
List<Integer> categoryTypeList = productInfoList.stream()
.map(e -> e.getCategoryType())
.collect(Collectors.toList());
List<ProductCategory> productCategoryList = categoryService.findByCategoryTypeIn(categoryTypeList);



        //传统方法
// for (ProductInfo productInfo : productInfoList) {
// categoryTypeList.add(productInfo.getCategoryType());
// }

还可以这么写

        List<CartDTO> cartDTOList = orderDTO.getOrderDetailList().stream().map(e ->
                new CartDTO(e.getProductId(), e.getProductQuantity())
        ).collect(Collectors.toList());
原文地址:https://www.cnblogs.com/gxlaqj/p/11658581.html