newList是个Value对象的List,orderId是Value对象的一个属性,现在要求根据orderId把List里的记录降序排序。使用 Collections.sort方法可实现此要求,需要自己写类实现Comparator的 compare接口,这里采用的内部类的方式,当然也可使用其他方式。
Collections.sort(newList, new Comparator<PropertyValue>(){
public int compare(Value p1, Value p2) {
final int count1 = p1.getOrderId();
final int count2 = p2.getOrderId();
return (count1 < count2 ? 1 : -1);
}
});