You could use this to sort all kind of Objects
sort(T[] a, Comparator<? super T> c) Arrays.sort(a, Collections.reverseOrder());
Arrays.sort()
cannot be used directly to sort primitive arrays in descending order. If you try to call the Arrays.sort()
method by passing reverse Comparator defined by Collections.reverseOrder()
, it will throw the error
no suitable method found for sort(int[],comparator)
That will work fine with ‘Array of Objects’ such as Integer array but will not work with a primitive array such as int array.
The only way to sort a primitive array in descending order is, first sort the array in ascending order and then reverse the array in place. This is also true for two-dimensional primitive arrays.
Related Posts:
- java Arrays.sort 2d array
- Will Arrays.sort() increase time complexity and space time complexity?
- How to sort an array of objects in Java?
- How to sort an array of objects in Java?
- Java, Simplified check if int array contains int
- How do I convert a String to an int in Java?
- Java – Convert integer to string [duplicate]
- How do I determine whether an array contains a particular value in Java?
- How to initialize an array in Java?
- Initialize part of an array in java
- How do I declare and initialize an array in Java?
- Convert list to array in Java [duplicate]
- Sort an array in Java
- What’s the simplest way to print a Java array?
- Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
- What’s the simplest way to print a Java array?
- How can I convert a char to int in Java? [duplicate]
- Converting array to list in Java
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- How to sort an ArrayList?
- “int cannot be dereferenced” in Java
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- Create ArrayList from array
- How to split a String by space
- Print ArrayList
- Print ArrayList
- Make copy of an array
- How to create a sub array from another array in Java?
- How to fix array index out of bounds error?
- How do I limit the number of decimals printed for a double?
- Why is there no SortedList in Java?
- How do I limit the number of decimals printed for a double?
- Double array initialization in Java
- Java – Best way to print 2D array?
- I want to declare an empty array in java and then I want do update it but the code is not working
- method in class cannot be applied to given types
- How to convert an ArrayList containing Integers to primitive int array?
- Convert an integer to an array of characters : java
- How to efficiently remove duplicates from an array without using Set
- Print ArrayList
- Convert array of strings into a string in Java
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- How to create an empty array?
- Finding the max/min value in an array of primitives using Java
- How to check whether a int is not null or empty?
- Java – Best way to print 2D array?
- What is the difference between a null array and an empty array?
- method in class cannot be applied to given types
- How can I create an Array of ArrayLists?
- Are arrays passed by value or passed by reference in Java?
- What is the difference between Integer and int in Java?
- How can I check whether an array is null / empty?
- Shifting array to the right – homework
- Add an object to an Array of a custom class
- what is Ljava.lang.String;@
- “Cannot create generic array of ..” – how to create an Array of Map
? - Sort a Map
by values - Convert String to int array in java
- “Actual or formal argument lists differs in length”
- Java Comparator class to sort arrays
- Resize an Array while keeping current elements in Java?
- List of Arrays in Java
- local variables referenced from an inner class must be final or effectively final
- Bank Account Java Program
- Java, Shifting Elements in an Array
- Counting an Occurrence in an Array (Java)
- How to make an array of arrays in Java
- Empty an array in Java / processing
- JAVA Variable declaration not allowed here
- Error: Generic Array Creation
- How to print the data in byte array as characters?
- Java read file and store text in an array
- (Java) Tic-Tac-Toe game using 2 dimensional Array
- int cannot be converted to int []
- Finding the size of a char array in Java
- Any way to declare an array in-line?
- Getting the array length of a 2D array in Java
- Get only part of an Array in Java?
- Checking to see if array is full
- Sort ArrayList of custom Objects by property
- How to use ArrayUtils for array of objects, it doesn’t delete the content of an array
- Error array dimension missing
- Printing char arrays in Java
- Determine if a String is an Integer in Java [duplicate]
- Fill an array with random numbers [duplicate]
- Convert boolean to int in Java
- How to sort a HashSet?
- Create a two dimensional string array anArray[2][2]
- Printing array elements with a for loop
- How do I convert this for loop into a while loop?
- How do I initialize a byte array in Java?
- How do you set one array’s values to another array’s values in Java?
- java.lang.ArrayIndexOutOfBoundsException: 0
- How to increase the size of an array in Java?
- Using insertion sort for descending order?
- How to Convert Int to Unsigned Byte and Back
- Java – Change int to ascii
- How to get rows and columns count of a 2D array in Java?
- Multidimensional Arrays lengths in Java