过年啦

根据对象的某个属性(这里是getUnit方法返回的值)进行分组,然后对每组中的对象的另一个属性(getUpdatedWeight方法返回的值)进行求和操作

Map<Integer, Long> integerLongMap = categoryList.stream()
            .collect(
                    Collectors.groupingBy(
                            DeliverRecordCategoryDto::getUnit, 
                            Collectors.summingLong(DeliverRecordCategoryDto::getUpdatedWeight))
            );

posted @ 2024-03-06 15:03  一只快乐的柠檬精J  阅读(49)  评论(0)    收藏  举报