public class SortStrings
1: import java.util.Arrays;
3: /**
4: * A program to sort lines according to their natural sorting order --
5: * whatever that may be!
6: *
7: * @author Mark Young (A00000000)
8: */
9: public class SortStrings {
11: public static void main(String[] args) {
12: // create list of Students
13: String[] ss = new String[] {
14: "bravo",
15: "Charlie",
16: "alpha",
17: "Zulu",
18: "echo",
19: "zany",
20: "November"
21: };
23: // report original
24: System.out.println("\nHere is a list of Strings:");
25: System.out.println("\t" + Arrays.toString(ss));
27: // sort and present sorted
28: Arrays.sort(ss);
29: System.out.println("\nHere is that same list, sorted:");
30: System.out.println("\t" + Arrays.toString(ss));
31: System.out.println();
33: // sort and present sorted
34: Arrays.sort(ss, String.CASE_INSENSITIVE_ORDER);
35: System.out.println("\nHere is that same list, sorted alphabetically:");
36: System.out.println("\t" + Arrays.toString(ss));
37: System.out.println();
39: // sort and present sorted
40: Arrays.sort(ss, (one, other) -> one.length() - other.length());
41: System.out.println("\nHere is that same list, sorted by length:");
42: System.out.println("\t" + Arrays.toString(ss));
43: System.out.println();
44: }
46: }