用这个工具类Collections.sort(list)(当然你可以用Arrays排序数组,我说的集合)
其中的list需要是实现了Comparable<T>
重写方法:
@overrite
public int compareTo(T o){
if(o == null){
return -1;
}
if (this == o)
return 0;
return this.name.compareTo(o.name);
}
用这个工具类Collections.sort(list)(当然你可以用Arrays排序数组,我说的集合)
其中的list需要是实现了Comparable<T>
重写方法:
@overrite
public int compareTo(T o){
if(o == null){
return -1;
}
if (this == o)
return 0;
return this.name.compareTo(o.name);
}