技术就是力量,没有对比就没伤害
六万条数据构建树结构,采用传统构建树方法和.stream()函数构建的对比!!!
1、拷贝的递归树逻辑(强烈不推荐)
public static List<CompanyInfo> listToTree(List<CompanyInfo> list) {
//用递归找子。
List<CompanyInfo> treeList = new ArrayList<CompanyInfo>();
for (CompanyInfo tree : list) {
//如果根目录的parentId为-1
if (tree.getParentId() == -1 ) {
treeList.add(findChildren(tree, list));
}
}
return treeList;
}
private static CompanyInfo findChildren(CompanyInfo tree, List<CompanyInfo> list) {
for (CompanyInfo node : list) {
if (node.getParentId().longValue() == tree.getId().longValue()) {
if (