当比较器降序排序时,这是如何实现升序排序的吗?
// Sorts the emails alphabetically by subject in ascending order.
public void sortBySubjectAscending()
{
Collections.sort(emails, Collections.reverseOrder(new Email.SubjectDescendingComparator()));
}
最佳答案
是的,确实如此。如果反转降序比较器,则会得到升序比较器。
要分解它,这就是你正在做的:
Comparator ascending = Collections.reverseOrder(new Email.SubjectDescendingComparator());
Collections.sort(emails, ascending);
关于java - 当比较器降序排序时,这是如何实现升序排序的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10320310/