Android List 排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/rrrgy236116/article/details/73462004

1.T排序

List<GroupBean> groupBeans ;


Collections.sort(groupBeans,new Comparator<GroupBean>(){

            public int compare(GroupBean arg0, GroupBean arg1) {
                return new Integer(arg0.sortno).compareTo(arg1.sortno);
            }

        });


        for(GroupBean u : groupBeans){
        Log.e("排序", u.sortno+" "+u.groupname);

        }


2. 字符串

ArrayList list =  new  ArrayList();
     list.add( "92.8" );
     list.add( "68.9" );
     list.add( "168.61" );
     list.add( "242" );
     list.add( "317" );
     list.add( "105" );
     // 字符串排序
     Collections.sort(list);
     System.out.println(list.toString());  // [105, 168.61, 242, 317, 68.9, 92.8]
    //double排序
     Collections.sort(list,  new  Comparator() {
       @Override
       public  int  compare(Object o1, Object o2) {
         return  new  Double((String) o1).compareTo( new  Double((String) o2));
       }
     });
     System.out.println(list.toString());  // [68.9, 92.8, 105, 168.61, 242, 317]
   }

猜你喜欢

转载自blog.csdn.net/rrrgy236116/article/details/73462004
今日推荐