0

Possible Duplicate:
Sort on a string that may contain a number

I'm implementing a custom sorting algorithm for a homework assignment, and I want it to sort strings with numbers attached at the end in proper order... As it is right now, "Book1" is coming after "Book10".

I'm using String.compareTo() to get the ordering, but I don't see a version of compareTo() that lets me choose any special kind of ordering.

Thanks.

Community
  • 1
  • 1
Mirrana
  • 1,601
  • 6
  • 28
  • 66

1 Answers1

0

You have to write your own implementation of Comparator that:

  • Splits the leading string from the trailing number.
  • Compares the leading strings for equality.
  • If equal, compares the trailing numbers for equality.
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111