JDK1.8新属性lambda

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



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

 

还可以这么写

        List cartDTOList = orderDTO.getOrderDetailList().stream().map(e ->
                new CartDTO(e.getProductId(), e.getProductQuantity())
        ).collect(Collectors.toList());

 

你可能感兴趣的