java list 数组对某个属性进行排序

405 阅读1分钟
//在实体类中需要实现Comparable<实体类>
在实体类中实现方法
public int compareTo(ShopProduct o) {
        // TODO Auto-generated method stub
        return Integer.valueOf(o.getSales()) - Integer.valueOf(this.sales);
    }
在业务逻辑中的使用方法为:
 Collections.sort(list数组);