Java例子:使用Comparator排序列表
Collections.sort() method is overloaded and we can also provide our own Comparator implementation for sorting rules. Since Comparator is a functional interface, we can use lambda expressions to write its implementation in a single line.
例子:
Collections.sort(dl, (d1, d2) -> {
return d2.getId() - d1.getId();
});
System.out.println("Reverse Sorted List using Comparator::" + dl);
输出:
