【发布时间】:2011-10-15 08:57:03
【问题描述】:
我有这个清单:
List<Country> countryList = new ArrayList<Country>();
我想使用getCountry() 方法按国家/地区的名称对它们进行排序。
如何做到这一点?
更新:
public class Country implements Comparable
@Override
public int compareTo(Object another) {
// TODO Auto-generated method stub
return 0;
}
你能告诉如何比较它们以使其按字符串排序吗? 阿根廷, 奥地利, 巴西等
【问题讨论】:
-
对于您的更新,您可以在
Comparable中使用泛型,因此,您应该实现Comparable<Country>,然后您将拥有compareTo(Country other)。从那里,您有两个对象,但是可以实现比较。 -
感谢您的回复
标签: java collections arraylist