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
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复