Sort List<T> of objects by a particular rule?
问题 I have this list: List<Country> countryList = new ArrayList<Country>(); And I want to sort the countries by their name, by using the method getCountry() . How can achieve this? UPDATE: public class Country implements Comparable @Override public int compareTo(Object another) { // TODO Auto-generated method stub return 0; } Can you tell how to compare them to get it sorted by Strings? Argentina, Austria, Brazil, etc. 回答1: There are two ways: Have Country implement the java.util.Comparable