List時間ソート、重複除外


ガイド:1.listコレクションをどのようにソートするか、直接コードをつけるか、簡単です.多くは言いませんが、Collections.sort()ソート方法を使用します.
 Collections.sort(list,new Comparator(){
            @Override
            public int compare(CallBackUtils callBackUtils, CallBackUtils t1) {
                SimpleDateFormat simpleDateFormat1 =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date1= null;
                int timeStemp1;
                SimpleDateFormat simpleDateFormat2 =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date2= null;
                int timeStemp2;
                try {
                    date1 = simpleDateFormat1 .parse(callBackUtils.getTime());
                    timeStemp1 = (int) date1.getTime();
                    date2 = simpleDateFormat1 .parse(t1.getTime());
                    timeStemp2 = (int) date2.getTime();
                    if(timeStemp1>timeStemp2){
                      //(return 1   )              long ,    。    ,   ,       。
                        return 1;

                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return -1;
            }

1.listに重複をどのように除去するか、setを使う方法もありますが、私たちのポインタアドレスkeyが異なると、setも機能しなくなります.私たちは愚かな方法で、双方向の循環で重複を除去します.
 //list      
    public static List removeRepeat(List ChatRecodeList){
        for(int i = 0;ifor(int j = ChatRecodeList.size()-1;j>i;j--){
//                   。                if((ChatRecodeList.get(i).getLid()+"").equals((ChatRecodeList.get(j).getLid()+""))){ 
                    ChatRecodeList.remove(j);
                }
            }
        }
        return removeRepeat;
        }