01: import java.util.*;
02: 
03: public class ComparatorTester
04: {
05:    public static void main(String[] args)
06:    {
07:       ArrayList<Country> countries = new ArrayList<Country>();
08:       countries.add(new Country("Uruguay", 176220));
09:       countries.add(new Country("Thailand", 514000));
10:       countries.add(new Country("Belgium", 30510));
11: 
12:       Collections.sort(countries, new
13:          Comparator<Country>()
14:          {
15:             public int compare(Country country1, Country country2)
16:             {
17:                return country1.getName()
18:                   .compareTo(country2.getName());
19:             }
20:          });
21: 
22:       // Now the array list is sorted by name
23:       for (Country c : countries)
24:          System.out.println(c.getName() + " " + c.getArea());
25:    }
26: }
27: