Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : How to sort an array of floats in reverse order?

I use the following lines to sort an array of floats in reverse order, but I got an error message, what's wrong ?

float sortedData[]=new float[100];
  ...
Arrays.sort(sortedData,Collections.reverseOrder());

Error : cannot find symbol

symbol : method sort(float[],java.util.Comparator) location: class java.util.Arrays Arrays.sort(sortedData,Collections.reverseOrder());

=========================================================================

I was confused because in Jdk1.6 api, I saw this : [ Arrays ] public static void sort(float[] a), it doesn't say : public static void sort(Float[] a)

like image 210
Frank Avatar asked Dec 30 '22 16:12

Frank


1 Answers

That specific method, takes an array of type Object. The type float does not extend the Object class, but Float does.

Float sortedData[]=new Float[100];
...
Arrays.sort(sortedData,Collections.reverseOrder());
like image 126
crunchdog Avatar answered Jan 12 '23 06:01

crunchdog