我是靠谱客的博主 强健云朵,这篇文章主要介绍list实现对Customer中某一属性字段排序从小到大展示,现在分享给大家,希望可以做个参考。

Customer类实现Comparable接口,

public class Customer implements Comparable<Customer>{

private int age;

```

public int compareTo(Customer o){

   if(this.age>=o.getAge())

        retrun 1;

}

retrun -1;

}

 

List<Customer> list=new ArrayList<Customer>();

list.sort(Comparator.naturalOrder());//从小到大排序

 

最后

以上就是强健云朵最近收集整理的关于list实现对Customer中某一属性字段排序从小到大展示的全部内容,更多相关list实现对Customer中某一属性字段排序从小到大展示内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部