lukeb28 lukeb28 - 1 year ago 119
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).

Answer Source

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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download