-1

I was trying to sort an array called efficiency in descending order just like this:

Arrays.sort(efficiency, (a, b) -> b - a)

However, it throws an exception that no suitable method has been found. I then check the Documentation and found that there actually is the method

    sort​(T[] a, Comparator<? super T> c)

What's wrong with that?

xunmiw
  • 21
  • 3

1 Answers1

0

Assuming the array has a non-primitive datatype, you could use the following:

Arrays.sort(efficiency, Collections.reverseOrder());

For a lambda specific approach I would check out this detailed answer:

https://stackoverflow.com/a/21970805/10171575

wareisjared
  • 330
  • 1
  • 2
  • 17