Collections.sort(list,Comparator.nullsFirst(Comparator.comparing(Person::getName,Comparator.nullsFirst(String::compareToIgnoreCase))));
将list按照元素的某个属性排序,并将该属性为null的值放在首位
最新推荐文章于 2024-08-14 23:12:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)
Collections.sort(list,Comparator.nullsFirst(Comparator.comparing(Person::getName,Comparator.nullsFirst(String::compareToIgnoreCase))));