获取树形结构

private List<Division> makeTree(List<?> list, String parentId){
        //子类
        List<Division> children = list.stream().filter(x -> x.getParentId().equals(parentId)).collect(Collectors.toList());
        //非子类
        List<Division> successor = list.stream().filter(x -> !x.getParentId().equals(parentId)).collect(Collectors.toList());
        children.forEach(x->{
            makeTree(successor,x.getId()).forEach(
                    y->x.getChildrenList().add(y)
            );
        });
        return children;
    }
posted @ 2023-07-10 10:02  striver-sc  阅读(9)  评论(0编辑  收藏  举报