Since you are sorting your entries as String
, its not behaving as numeric sorting as in character notiation, .
(ASCII 46) comes before m
(ASCII 109) hence 5.5mm
is moved up than 5mm
.
Create another decimal point list by stripping the mm
, sort the new decimal list as below:
List<BigDecimal> decimalList = new ArrayList<BigDecimal>();
for(String elem: myList){
decimalList.add(new BigDecimal(elem.substring(0, elem.length()-2)));
}
Collections.sort(decimalList);
If you want, recreate your sorted string list back as:
myList.clear();
for(BigDecimal elem: decimalList){
myList.add(elem.doubleValue()+"mm");
}