jdk1.8 list特性

 

LIST分组

Map<String,CommodityVO> map = new HashMap<>();

        List<CommodityVO> list = dao.list(applyId);
        if (CollectionUtil.isNotEmpty(list)) {
            map = list.stream().collect(Collectors.toMap(x -> x.getCommodityId() ,Function.identity()));
        }

 

多字段去重

List<CatTest> catList = Lists.newArrayList();
catList.stream()
        .collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(cat -> cat.getCarHobby() + cat.getCatName()))),
                        ArrayList::new
                )
        );

 

posted on 2024-03-05 16:40  lewisat  阅读(4)  评论(0编辑  收藏  举报

导航