Sorting numbers as strings
843810Apr 4 2008 — edited Jan 12 2010This may be in the wrong forum; please let me know if it is.
OK... I'm trying to build an alphabetizing program for a small organization in my town. I've finally got one to work, but it has a problem: It doesn't sort any numbers properly, which isn't entirely surprising, nonetheless...
The Collections.sort() method which I use on my vectors sorts a set like
1, 2, 5, 8, 10, 20, 50, 79
like
1, 10, 2, 20, 5, 50, 79, 8.
I'm not entirely surprised by this, I just don't have any idea to fix it. The problem is that the alphabetizer is supposed to sort names and numbers together seamlessly, so simply using Integers is not an option. I need to be able to sort things like
Davis, 10 Davis, 2 Davis, 10 Smith, Smith, etc...
Is there a built-in method that will accomplish this, or will I have to think up some sort of method for it?
Thanks in advance.