MyObject:
long id;
long parentId;
long index;
List<MyObject> child;顶级parentId = 0.....如何根据index排序。。。。现在好像是 默认的字典排序
3 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
Java排序,Java8方法
外层排序直接
list.sort(Comparator.comparing(t -> ((MyObject) t).getIndex()));
外层排序好了过后再循环排序里面的
list.forEach(t->{ ((MyObject)t).getChild().sort(Comparator.comparing(MyObject::getIndex)); });
Smart猫小萌
TA贡献1911条经验 获得超7个赞
private List<TextbookChapterTreeBO> children; public List<TextbookChapterTreeBO> getChildren() { children.forEach(t->{ ((TextbookChapterTreeBO)t).getChildren().sort(Comparator.comparing(TextbookChapterTreeBO::getIndex)); }); return children; } public void setChildren(List<TextbookChapterTreeBO> children) { this.children = children; }
把这个排序加到bean里就行了
添加回答
举报
0/150
提交
取消