I have an string arraylist with values like
2.25mm
2.75mm
5mm
5.5mm
When sorting the values that do not have decimal place sort incorrectly.
5.5mm proceeds 5mm where 2.25mm correctly proceeds 2.75mm
I have not had any experience with comparator so any help would be much appreciated.
Since you are sorting your entries as
String, its not behaving as numeric sorting as in character notiation,.(ASCII 46) comes beforem(ASCII 109) hence5.5mmis moved up than5mm.Create another decimal point list by stripping the
mm, sort the new decimal list as below:If you want, recreate your sorted string list back as: