Hey, I am trying too sort an arraylist with numbers in it. I wanted to use the collections sort to do this but it only looks at the first number for some reason. I want it to look at the whole number and sort it accuratly
ex: if numbers are 1,21,2,15,3
when it should print
Whats up? thanks.
Message was edited by:
You're sorting strings, not numbers, apparantly.
"1" (as a String) is 'less than' "15", which is 'less than' "2", etc.
If your collection actually had Integers in it instead of Strings, I bet it would work as you would expect it to.
Ya I didnt even think of that, you are correct. The reason I have it as strings is because they are not just numbers in the cells, its more like this.
so I have both, I guess my only choice is to make 2 arraylists? One with the words and one ints?
No, you should define a class that has 1 and "One" as fields. Make that class implement Comparable or provide a Comparator.