public class CreateOrgTreeUtil { public static List<OrgDTO> CreateTree(int parentId, List<OrgDTO> treeEntityList) { return treeEntityList.stream() .filter(treeEntity -> treeEntity.getNmParentid()==parentId) .peek(treeEntity -> treeEntity.setChildren(CreateTree(treeEntity.getNmId(), treeEntityList))) .collect(Collectors.toList()); } }