处理没有关联的数据为菜单

public class user {
    private String type;

    private String year;

    private String org;

    private List<user> userList;
    public user(String type, String year, String org) {
        this.type = type;
        this.year = year;
        this.org = org;
    }

    public user() {

    }
   
 public static void main(String[] args) {
        final user user1 = new user("审核通过", "2022", "编制");
        user user2 = new user("审核通过", "2023", "编制");
        user user3 = new user("审核不通过", "2022", "编制");
        user user4 = new user("审核不通过", "2023", "编制");
        user user5 = new user("审核不通过", "2024", "编制");
        List<user> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);
        list.add(user5);

        Map<String, List<user>> collect = list.stream().collect(Collectors.groupingBy(user -> user.getType()));

        final Set<Map.Entry<String, List<user>>> entries = collect.entrySet();
        List<user> list1 = new ArrayList<>();
        final Iterator<Map.Entry<String, List<user>>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            final Map.Entry<String, List<user>> next = iterator.next();
            final user userVO = new user();
            userVO.setType(next.getKey());
            userVO.setUserList(next.getValue());
            list1.add(userVO);
        }
        for (user vo : list1) {

            final List<user> userList = vo.getUserList();
            List<user> list2 = new ArrayList<>();
            final Map<String, List<user>> collect1 = userList.stream().collect(Collectors.groupingBy(user -> user.getYear()));
            final Iterator<Map.Entry<String, List<user>>> iterator1 = collect1.entrySet().iterator();
            while (iterator1.hasNext()) {
                final Map.Entry<String, List<user>> next = iterator1.next();
                user userVO = new user();
                userVO.setYear(next.getKey());
                //处理value
                userVO.setUserList(next.getValue());
                list2.add(userVO);
            }
            vo.setUserList(list2);

        }

        System.out.println(list1);


        //user user6 = new user("审核通过","2022","编制");
    }

在这里插入图片描述
打印内容
[user(type=审核通过, year=null, org=null, userList=[user(type=null, year=2023, org=null, userList=[user(type=审核通过, year=2023, org=编制, userList=null)]), user(type=null, year=2022, org=null, userList=[user(type=审核通过, year=2022, org=编制, userList=null)])]), user(type=审核不通过, year=null, org=null, userList=[user(type=null, year=2024, org=null, userList=[user(type=审核不通过, year=2024, org=编制, userList=null)]), user(type=null, year=2023, org=null, userList=[user(type=审核不通过, year=2023, org=编制, userList=null)]), user(type=null, year=2022, org=null, userList=[user(type=审核不通过, year=2022, org=编制, userList=null)])])]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值