-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?

1
  • 1
    Can you please post more details like, how your array 'efficiency' is initialized ? what type of elements does the array hold ? Commented Mar 16, 2020 at 5:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.