//在实体类中需要实现Comparable<实体类>
在实体类中实现方法
public int compareTo(ShopProduct o) {
// TODO Auto-generated method stub
return Integer.valueOf(o.getSales()) - Integer.valueOf(this.sales);
}
在业务逻辑中的使用方法为:
Collections.sort(list数组);
复制代码
转载于:https://juejin.im/post/5ce660e7e51d455071250a7e