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.

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

1 Comment

Nice link although one should really fix stuff like "file05" coming AFTER "file1". Actually I think I'll mail him the trivial fix.

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.