java递归遍历树结构目录

目录实体

private int id;
    private int pid;
    private String name;

递归遍历方法

private void getTree(Menu menu ,List menus){
        int pid = menu.getId();
        List childs = null;
        Iterator iterator = menus.iterator();
        while (iterator.hasNext()) {
            Menu m = iterator.next();
            if(m.getPid() == pid){
                childs = menu.getChild();
                if(childs == null)
                    childs = new ArrayList();
                childs.add(m);
                iterator.remove();
                menu.setChild(childs);
            }
        }
        if(childs != null && !childs.isEmpty() && menus !=null && !menus.isEmpty()){
            Iterator iterator2 = childs.iterator();
            while(iterator2.hasNext()){
                Menu next = iterator2.next();
                getTree(next,menus);
            }
        }
    }

 ----------------------------------------------------------------------------------------邪恶的分隔线-------------------------------------------------------------------------------------------------

这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数这是凑字数

你可能感兴趣的:(java递归遍历树结构目录)