Sort an ArrayList of Strings that are numbers

后端 未结 6 1684
孤街浪徒
孤街浪徒 2021-01-18 02:05

What is the fastest way to sort an ArrayList (in descending/ascending manner) that contains numbers, eg: { \"12\", \"3.5\", \"188\", \"33.03

6条回答
  •  暖寄归人
    2021-01-18 02:30

    You can use Collections.sort() on List, String is Comparable, but that comparison won't give you the right result.

    Also you can define your own Comparator, and pass it to Collections.sort().

提交回复
热议问题