For primitive array types, you will have to write a reverse sort algorithm:
Alternatively, you can convert int[] to Integer[] and write a comparator:
public class IntegerComparator implements Comparator<Integer> { @Override public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); } }
or use Collections.reverseOrder() as it only works with non-primitive array types.
and finally
Integer[] a2 = convertPrimitiveArrayToBoxableTypeArray(a1); Arrays.sort(a2, new IntegerComparator());
source share