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

前端 未结 12 1791
刺人心
刺人心 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:42

    The Collections.sort() method's docs says:

    Sorts the specified list into ascending order, according to the natural ordering of its elements.

    Which means for Strings that you are going to get the list in alphabetic order. The String 11_assign_privileges.sql comes before the string 1_create_table.sql and 12_07_insert_static_data.sql comes before 1_create_table.sql etc. So the program is working as expected.

提交回复
热议问题