当前位置:   article > 正文

stream流实现从List 集合中取出对象中相同属性的值存放到新的list集合中,返回map结构_list.stream.map返回新的对象

list.stream.map返回新的对象
@RequestMapping("list2")
    @ResponseBody
    public List<Map<Long, List<PlanDO>>> getList2() {

        List<PlanDO> list = new ArrayList<>();

        list.add(new PlanDO(1l,1l,"0",new Date()));
        list.add(new PlanDO(2l,116l,"0",new Date()));
        list.add(new PlanDO(3l,118l,"0",new Date()));
        list.add(new PlanDO(6l,1l,"0",new Date()));
        list.add(new PlanDO(5l,116l,"0",new Date()));
        list.add(new PlanDO(4l,118l,"0",new Date()));
        
        Map<Long, List<PlanDO>> collect = list.stream().collect(Collectors.groupingBy(PlanDO::getUserId));
        List<Map<Long, List<PlanDO>>> maps1 = new ArrayList<>();
        maps1.add(collect);
        return maps1;
    }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/495182
推荐阅读
相关标签
  

闽ICP备14008679号