[color=white]
import java.util.*;
public class Sorter {
public static void main(String args[]) {
String array[] = {"this", "is", "a", "simple", "example"};
System.out.println("Unsorted:");
printArray(array);
sortStringArray(array);
System.out.println("\nSorted:");
printArray(array);
}
public static void sortStringArray(String array[]) {
String temp;
for (int counter = 0; counter < array.length - 1; counter++) {
for (int loc = 0; loc < array.length - counter - 1; loc++) {
// option: change "compareToIgnoreCase" to "compareTo"
// this will treat capital letters differently
if (array[loc].compareToIgnoreCase(array[loc + 1]) > 0) {
temp = array[loc];
array[loc] = array[loc + 1];
array[loc + 1] = temp;
}
}
}
}
public static void printArray(String array[]) {
for (int counter = 0; counter < array.length; counter++)
System.out.println("" + counter + ")\t" + array[counter]);
}
}
[/color]