实体类:
@Data
public class BoroughsVO {
private String parentId;
private String value;
private String label;
private List<BoroughsVO> children = new ArrayList<>();
}
需要将此list进行一个升序排列:
List<BoroughsVO> citys = xxx;
System.out.println(citys);
Collections.sort(citys, new Comparator<BoroughsVO>() {
@Override
public int compare(BoroughsVO o1, BoroughsVO o2) {
int mark = 1;
if (Long.valueOf(o1.getValue()) < Long.valueOf(o2.getValue())) {
mark = -1;
}
return mark;
}
});
System.out.println(citys);
智能的IDEA提示我用lambda代替........
Collections.sort(citys, (o1, o2) -> {
int mark = 1;
if (Long.valueOf(o1.getValue()) < Long.valueOf(o2.getValue())) {
mark = -1;
}
return mark;
});
|