1  import java.util.ArrayList;
  2  import java.util.Arrays;
  3  import java.util.Collections;
  4  
  5  /**
  6     This program demonstrates Java library methods for sorting and
  7     searching.
  8  */
  9  public class JavaLibraryDemo
 10  {
 11     public static void main(String[] args)
 12     {
 13        int[] values = { 1, 4, 9, 1, 6, 2, 5, 3, 6, 4, 9, 6, 4, 8, 1 };
 14        Arrays.sort(values);
 15        System.out.println(Arrays.toString(values));
 16        int pos = Arrays.binarySearch(values, 4);
 17        System.out.println("Position of 4: " + pos);
 18        pos = Arrays.binarySearch(values, 7);
 19        System.out.println("Position for inserting 7: " + (-pos - 1));
 20  
 21        Country country1 = new Country("Belgium", 30510);
 22        Country country2 = new Country("Thailand", 514000);
 23        Country country3 = new Country("Uruguay", 176220);
 24  
 25        ArrayList<Country> countries = new ArrayList<Country>();
 26        countries.add(country1);
 27        countries.add(country2);
 28        countries.add(country3);
 29  
 30        Collections.sort(countries);
 31        System.out.println(countries);
 32     }
 33  }