自然,这是您的选择。无论您编写什么逻辑,它都会定义排序规则。因此,“应该”在这里并不是正确的词。
如果您希望null出现在任何其他元素之前,则可以这样做
public int compare(MyBean o1, MyBean o2) { if (o1.getDate() == null) { return (o2.getDate() == null) ? 0 : -1; } if (o2.getDate() == null) { return 1; } return o2.getDate().compareTo(o1.getDate());}


