How can I sort this ArrayList the way that I want?

前端 未结 12 1784
刺人心
刺人心 2020-12-04 18:17

Here is a simple sorting program of an ArrayList:

ArrayList list = new ArrayList();

list.add(\"1_Update\");
list.add(\"11_Add\")         


        
12条回答
  •  星月不相逢
    2020-12-04 18:51

    As others have stated, the elements will be sorted alphabetically by default. The solution is define a concrete java.util.Comparator class and pass it as a second argument to the sort method. Your comparator will need to parse out the leading integers from the strings and compare them.

提交回复
热议问题