In case you're sure there aren't any null values in your list then you can omit the first nullsLast (as noted by @Holger) :list.sort(comparing(Bean::getVal, nullsLast(naturalOrder()))); 这篇关于Comparator.nullsLast不能避免NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-17 01:29