Java 对集合进行排序

public List compareTo(List<Object> result)throws Exception{
    Collections.sort(result,new Comparator<Object>(){
        public int compare(Object arg0, Object arg1) {
            if(arg0.getNumber()>arg1.getNumber()){
                return 1; 
            }else if(arg0.getNumber()<arg1.getNumber()){
                return -1; 
            }else{
                return 0; 
            }
        }
    });
    return result;
}

这里假设 Object  对象里有number 属性,对number 进行排序;

List result = compareTo(list);





你可能感兴趣的:(Java 对集合进行排序)