How to sort an array from highest to lowest? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to sort an array from highest to lowest?

Arrays.sort();

13th Nov 2019, 4:54 PM
John Emmanuel Piga
John Emmanuel Piga - avatar
6 Answers
13th Nov 2019, 9:04 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 3
Brother don't use methods in learning period, go for algorithms. Use Bubble sort, selection sort etc. It will strength your concept.
13th Nov 2019, 5:02 PM
Nitin Tiwari
Nitin Tiwari - avatar
+ 2
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). https://stackoverflow.com/questions/1694751/java-array-sort-descending
13th Nov 2019, 9:59 PM
Tibor Santa
Tibor Santa - avatar
0
John Emmanuel Piga There is a lot of sorting algorithms. Like Nitin Tiwari said firstly try bubble sort then try something more powerful.
13th Nov 2019, 8:21 PM
patos
patos - avatar
0
We can use bubble sort , quick sort mainly we can use merge sort which is the best
15th Nov 2019, 2:05 PM
Arjun T Raju
Arjun T Raju - avatar
0
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 ) );
21st Nov 2019, 6:53 PM
zemiak