Comparator进行排序
2014-01-24 13:40
211 查看
基础学习: http://www.360doc.com/content/08/0928/10/16915_1686535.shtml
比如我们有一个paymentVO 里面有好多属性 比如我们的需求就是根据里面的paymentSequenceNo进行升序、降序排列展示出来。
同理降序排列只要把上面的Collections.sort(..)改成Collections.reverse(...)即可.
比如我们有一个paymentVO 里面有好多属性 比如我们的需求就是根据里面的paymentSequenceNo进行升序、降序排列展示出来。
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void ascendingSort(List<PaymentVO> list) { if (!list.isEmpty()) { Collections.sort(list,new Comparator() { @Override public int compare(Object o1, Object o2) { PaymentVO nVo1 = (PaymentVO) o1; PaymentVO nVo2 = (PaymentVO) o2; return nVo1.getBankTradePaymentSeqNo().compareTo(nVo2.getBankTradePaymentSeqNo()); }}); } }
同理降序排列只要把上面的Collections.sort(..)改成Collections.reverse(...)即可.
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void desscendingSort(List<PaymentVO> list) { if (!list.isEmpty()) { Collections.reverse(list,new Comparator() { @Override public int compare(Object o1, Object o2) { PaymentVO nVo1 = (PaymentVO) o1; PaymentVO nVo2 = (PaymentVO) o2; return nVo1.getBankTradePaymentSeqNo().compareTo(nVo2.getBankTradePaymentSeqNo()); }}); } }
相关文章推荐
- iphone5s激活视频
- split命令:文件切割
- Oracle数据库查询高效分页
- xampp 无法启动appche mysql
- ORA-02041: client database did not begin a transaction
- hdu 2152 Fruit 有上下界的母函数
- 便签1.JS方法调用括号的问题
- Jquery元素追加和删除
- tiny2451 一线屏改四线屏 4000
- xmpp
- 内存分配
- centos 6.2下,部署jdk1.6
- 全球PM2.5分布图
- sendmail服务器案例配置
- CentOS6.3下配置NTP服务器
- vi 操作备忘
- C# set和get如何用
- ngnix之lnmp环境搭建及Dvbbs搭建
- 获取本周周一,周末 获取任意时间的周一周末
- java JAXB 学习