How to sort an array from highest to lowest? | SoloLearn: Learn to code for FREE!


How to sort an array from highest to lowest?


11/13/2019 4:54:17 PM

John Emmanuel Piga

6 Answers

New Answer


Here is implementation


Brother don't use methods in learning period, go for algorithms. Use Bubble sort, selection sort etc. It will strength your concept.


If your array contains objects, you can reverse sort easily: Arrays.sort(data, Collections.reverseOrder()); If your array contains primitive data types, it is more complicated, possibly by using streams, or converting to reference type (eg. int to Integer).


John Emmanuel Piga There is a lot of sorting algorithms. Like Nitin Tiwari said firstly try bubble sort then try something more powerful.


We can use bubble sort , quick sort mainly we can use merge sort which is the best


import java.util.Arrays; import java.util.Comparator; ... Integer[] aInt = {6,2,3,4,1,5,7,8,9,10}; Arrays.sort(aInt, Comparator.reverseOrder() ); System.out.println( Arrays.toString( aInt ) );