01: import java.util.*; 02: 03: public class ComparatorTest 04: { 05: public static void main(String[] args) 06: { 07: ArrayList countries = new ArrayList(); 08: countries.add(new Country("Uruguay", 176220)); 09: countries.add(new Country("Thailand", 514000)); 10: countries.add(new Country("Belgium", 30510)); 11: Comparator comp = new CountryComparatorByName(); 12: Collections.sort(countries, comp); 13: // now the array list is sorted by name 14: for (int i = 0; i < countries.size(); i++) 15: { 16: Country c = (Country) countries.get(i); 17: System.out.println(c.getName() + " " + c.getArea()); 18: } 19: } 20: } 21: