Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there any method to sort a string array in specific order in java which has alphanumeric elements in it

I have an array named "testArray" with elements: {"fdvsd","sd","Edit1648004502584","zxz","automatioion","acas","teg"}

Once I use Arrays.sort(testArray), the elements are sorted as below:
{"Edit1648004502584","acas","automatioion","fdvsd","sd","teg","zxz"}

But I need the array to be sorted as follows:
{"acas","automatioion","Edit1648004502584","fdvsd","sd","teg","zxz"}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please help me out.

>Solution :

If I understand correctly the issue you are having is the capitalisation of the Strings, when you want it to ignore case. Try the following code:

Arrays.sort(testArray, String::compareToIgnoreCase);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading