lukeb28 lukeb28 - 2 months ago 6
Java Question

Sorting an int array from highest to lowest

So I just learned about the

and applied it in a project of mine but I found it sorts from lowest to highest. Is there anyway to have it do the opposite? (I don't think I need to post the code in question but if it is needed I'll post it).


If you use an Integer[] instead of int[], then you can pass a Comparator as 2nd argument to the sort method. To impose reverse ordering, you can make use of Collections.reverseOrder() method:

Arrays.sort(arr, Collections.reverseOrder());