public class TestIntArraySort
1: //TestIntArraySort.java
2: //Illustrates sorting an array of values according to
3: //the "natural order" of those values. This example is
4: //here to remind you that when you start looking at the
5: //other files in this directory the first thing you need
6: //to note and remember is that Employee objects, unlike
7: //integer values, do not have any "natural order".
9: import java.util.Arrays;
11: public class TestIntArraySort
12: {
13: public static void main(String[] args)
14: {
15: System.out.println();
16: int[] intArray =
17: {
18: 7, 2, 9, 5, 3, 1
19: };
20: for (int i : intArray)
21: {
22: System.out.print(i + " ");
23: }
24: System.out.println();
26: Arrays.sort(intArray);
27: for (int i : intArray)
28: {
29: System.out.print(i + " ");
30: }
31: System.out.println();
32: }
33: }
34: /* Output:
36: 7 2 9 5 3 1
37: 1 2 3 5 7 9
38: */