list根据所存对象属性排序

比如有个list,里面存的是一个个对象,对象有个list属性,其值可以是字符串和数字。

 1 private void getSortList(List<AclResource> newList) {
 2         Collections.sort(newList, new Comparator<AclResource>() {
 3             @Override
 4             public int compare(AclResource o1, AclResource o2) {
 5                 if(o1.getList()>o2.getList()){
 6                     return 1;
 7                 }else if(o1.getList() == o2.getList()){
 8                     return 0;
 9                 }
10                 return -1;
11             }
12         });
13         
14     }

其中list里面存放的是AclResource对象。

posted @ 2016-12-02 11:40  皆木  阅读(990)  评论(0编辑  收藏  举报