sorting arrays Example
Arrays of primitive and reference types can simply be sorted in ascending sequence using the method Arrays.sort(). The Arrays class is part of the Java Collections Framework which provides advanced sorting and searching facilities. The method Arrays.toString() yields a string of array values.
Notice that uppercase characters are sorted before lowercase characters.
// Array Sorting Example
import java.util.*;
class ArraySortingExample {
public static void main(String[] args) {
int[] ia = {99, -17, 5};
Arrays.sort(ia);
System.out.println(Arrays.toString(ia));
String[] sa = {"To", "be", "or", "not", "to", "be"};
Arrays.sort(sa);
System.out.println(Arrays.toString(sa));
}
}
