Java: Example - String selection sort

This is a short example of using selection sort on a full array of Strings.


// Sort a String array using selection sort.
public static void sort(String[] a) {
  for (int i=0; i<a.length-1; i++) {
     for (int j=i+1; j<a.length; j++) {
        if (a[i].compareTo(a[j]) > 0) {
           String temp=a[j]; a[j]=a[i]; a[i]=temp;
        }
     }
  }
}