9.数据排序

来源:互联网 发布:中科大软件学院本科 编辑:程序博客网 时间:2024/05/05 09:31

转载请注明出处 http://blog.csdn.net/qq_31715429/article/details/50973368
本文出自:猴菇先生的博客

实现数据根据日期倒序排列
(1).在JavaBean中实现Comparable<Bean>接口,重写hashCode()、equals(Object obj)、 compareTo(PriceBean another)方法:

@Overridepublic int compareTo(PriceBean another) { if (another instanceof PriceBean) {  PriceBean priceBean = (PriceBean) another;  int comOfferday = priceBean.offerday.compareTo(this.offerday);  return comOfferday; } return 0;}

(2).在用到排序集合的地方:

 ArrayList<PriceBean> mContentList = new ArrayList<PriceBean>(); LogMessage.i("monkey", "价格排序前-->" + mContentList.toString()); Collections.sort(mContentList); LogMessage.i("monkey", "价格排序后-->" + mContentList.toString());
0 0
原创粉丝点击