public static void main(String[] args) {
List<Integer> sortList = new ArrayList<>();
sortList.add(3);
sortList.add(9);
sortList.add(6);
sortList.add(1);
for (Integer num: sortList) {
System.out.print(num+" ");
}
Collections.sort(sortList, new Comparator<Integer>() {
@Override
//o1-o2 从小到大 ,o2-o1 从大到小
public int compare(Integer o1, Integer o2) {
return o2-o1;
}
});
System.out.println("--------");
for (Integer num: sortList) {
System.out.print(num+" ");
}
}
List集合使用 Collections.sort 排序
猜你喜欢
转载自blog.csdn.net/xiaobanv1/article/details/85319027
今日推荐
周排行