list中对象按照属性排序

来源:互联网 发布:商友软件 编辑:程序博客网 时间:2024/05/16 07:48
//这里将li中元素排个序        Collections.sort(li, new Comparator<ClassDirTmp>() {            @Override            public int compare(ClassDirTmp o1, ClassDirTmp o2) {                if(Integer.parseInt(o1.getIndex()) > Integer.parseInt(o2.getIndex())){                    return 1;                }                if(Integer.parseInt(o1.getIndex()) == Integer.parseInt(o2.getIndex())){                   return 0;                }                return -1;            }        });
大于返回1,等于返回0,小于返回-1