In Java , I want to compare and sort strings that contain a character and a number. For example:
A15, D35, A17, C45, B27, C30 should be sorted
A15 A17 B27 C30 C45 D35. I am not really sure how to compare two of those elements because they contain a string and a number. Can anyone help me please?
If your numbers are always two digits, then simply compare the whole things as strings. Numbers in decimal are strings too.
It’s a different story if you need to sort A9, A54, and A123456 and want the numbers to sort by their numeric value. In that case you may need to write your own compare function that splits the string apart into its component parts.