Java的:我如何按照自然顺序进行排序的ArrayList? [英] Java: How do I sort an ArrayList according to a natural ordering?
本文介绍了Java的:我如何按照自然顺序进行排序的ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类我创建,每个包含字符串中的一个字段的实例的ArrayList。我在我创建的类实现可比。我如何排序的数组列表?
I have an ArrayList of instances of a class I created, each of which contains a single field with a String. I have implemented Comparable in the class I created. How do I sort the Array List?
推荐答案
<一个href=\"http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#sort%28java.util.List%29\"相对=nofollow> Collections.sort
修改结果
对我来说没有任何错误
edit
No errors for me
class Gene {
}
class MyGene extends Gene implements Comparable<MyGene> {
public int compareTo(MyGene o) {
throw new UnsupportedOperationException("Method is not implemented yet.");
}
}
...
List<MyGene> l = new ArrayList<MyGene>();
Collections.sort(l);
这篇关于Java的:我如何按照自然顺序进行排序的ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文