CountrySortTest.javaimport java.util.*;
public class CountrySortTest
{
public static void main(String[] args)
{
ArrayList countries = new ArrayList();
countries.add(new Country("Uruguay", 176220));
countries.add(new Country("Thailand", 514000));
countries.add(new Country("Belgium", 30510));
Collections.sort(countries);
// now the array list is sorted by area
for (int i = 0; i < countries.size(); i++)
{
Country c = (Country) countries.get(i);
System.out.println(c.getName() + " " + c.getArea());
}
}
}
>java CountrySortTest Belgium 30510.0 Uruguay 176220.0 Thailand 514000.0
Maintained by John Loomis, updated Fri Feb 23 17:47:34 2007