Arrays.sort(T[] a, Comparator <? super T> c) has the following syntax.
public static <T> void sort(T[] a, Comparator <? super T> c)
In the following code shows how to use Arrays.sort(T[] a, Comparator <? super T> c) method.
//from w w w .j a v a 2 s .c o m import java.util.Arrays; import java.util.Collections; import java.util.Comparator; public class Main { public static void main(String[] args) { // initializing unsorted short array Short[] sArr = new Short[]{3, 13, 1, 9, 21}; System.out.println(Arrays.toString(sArr)); // create a comparator Comparator<Short> comp = Collections.reverseOrder(); // sorting array with reverse order using comparator Arrays.sort(sArr, comp); System.out.println(Arrays.toString(sArr)); } }
The code above generates the following result.