Alphabetical order
If you wish to view the code only, check this page. You can click the links and it should open up in a notepad file.
import java.util.*;
class MyNames {
public static void main(String[] arguments) {
String names[] = { "Jeff", "Bob", "Billy", "Jim",
"Fish", "Peter", "Chris", "Lois", "Stewie", "Meg", "Chruch",
"Caboose", "Grif", "Tex", "Tucker", "Doc" };
System.out.println("The original order:");
for (int i = 0; i < names.length; i++)
System.out.println(i + ": " + names[i]);
Arrays.sort(names);
System.out.println("The new order:");
for (int i = 0; i < names.length; i++)
System.out.println(i + ": " + names[i]);
}
}
Code taken from:
http://www.samspublishing.com/library/content.asp?b=STY_Java2_24hours&seqNum=107&rl=1