For example, Tweet entity has two properties: Id, tweetCreateDate. I have a list of tweets, I need to sort them by tweetCreateDate desc. Here is the way I do it.
Collections.sort(tweets, new Comparator<Tweet>() {
public int compare(Tweet t1, Tweet t2) {
return t2.getTweetCreateDate().compareTo(t1.getTweetCreateDate());
}
});
本文展示了如何使用Java的Collections.sort方法和Comparator接口,根据推文的创建日期对推文列表进行降序排序。
792

被折叠的 条评论
为什么被折叠?



