Originally posted by Henry Wong:
It shouldn't be that hard to write one... Just create a Comparator that takes strings, whose compare() method, converts the string to either int, float, or double, and then route the request to the Integer, Float, or Double class as the comparator.
Henry
I hate when I get in a hurry and leave one of the most critical parts out.
Suppose you are sorting addresses:
- 1 Main St
- 7 Main St
- 9 Main St
- 11 Main St
- 30 Main St
A simple string sort would turn this into:
- 1 Main St
- 11 Main St
- 30 Main St
- 7 Main St
- 9 Main St
So what we have here is a two part comparison: the number and the string. The number is the more important part, but after the number comes the text part of the string.
Is there a better way than splitting the string (probably via regexp)?