Sorting a BigInteger array

5 views (last 30 days)
Michelle Lear
Michelle Lear on 29 Apr 2022
Commented: Jan on 2 May 2022
I need to sort an array but the contents are BigIntegers. When I try use the "sort(A)" function I get the following error:
Error using sort
Unknown command option.
Is it because the array is type BigInteger[] ? And if that's the case, how can I sort it?

Accepted Answer

Jan
Jan on 29 Apr 2022
How dod you create the array? Please post a short example. I seems that you are talking about a Java class, not a Matlab array. Then use a Java method for sorting...
FEX: HPF might be useful. It has implemented an merge sort.
  4 Comments
Michelle Lear
Michelle Lear on 30 Apr 2022
I have tried what you wrote in your comment and I get the following :
No method
'java.util.Collections.sort' with
matching signature found.
I imported java.util.* but that doesn't change the outcome.
Jan
Jan on 2 May 2022
@Michelle Lear: The link does not uniquely explain, how you have defined your array of BigIntegers. It would be helpful if you post your code instead of letting me guess the details.
I've showed you the code to inster the BigIntegers in a java.util.ArrayList, and this is a valid input for java.util.Collections.sort. If you use the suggested method, you will not get this error message.

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!