2

Let's say I'm trying to sort the following array.

String[] array = { "ABC12", "ABC1", "ABC0" "ABC9"}

Sorting using Arrays.sort(array), it becomes {"ABC0", "ABC1", "ABC12", "ABC9"}

However, I want to sort alphabetically by letters AND numerically by numbers appending "ABC" such that array becomes {"ABC0", "ABC1", "ABC9", "ABC12"}. Is there an existing method to do this?

1 Answer 1

6

You're looking for an AlphaNumeric sort like this one.

1
  • Nice link although one should really fix stuff like "file05" coming AFTER "file1". Actually I think I'll mail him the trivial fix.
    – Voo
    Commented Nov 9, 2011 at 17:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.