如何使用集合和比较器按升序对Arraylist进行排序 [英] how to sort an Arraylist in ascending order using using Collections and comparator

查看:230
本文介绍了如何使用集合和比较器按升序对Arraylist进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组列表,如何使用Comparator按升序排序?我知道如何按降序排序:

I have an arraylist, how can use Comparator to sort it in ascending order? I know how to sort it in descending order using:

Comparator mycomparator = Collections.reverseOrder();

然后

Collections.sort(myarrayList,mycomparator);

只是想知道如何使用集合和比较器以升序排序?谢谢!

just want to know how to sort it in ascending order using Collections and comparator? Thanks!

推荐答案

只是把它抛出来...你不能这么做:

Just throwing this out there...Can't you just do:

Collections.sort(myarrayList);

过了一段时间...

这篇关于如何使用集合和比较器按升序对Arraylist进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆