How to sort an ArrayList based on specific index range

前端 未结 2 1664
滥情空心
滥情空心 2021-01-18 07:13

My need is to sort the ArrayList of Strings, based on specific index range. For example I have following items in list: [\"abc\", \"xyz\", \"pqr\" , \"asd\"]Now

2条回答
  •  盖世英雄少女心
    2021-01-18 07:45

    You should do

    Collections.sort(yourList.subList(1, yourList.size()));
    

    Since the List.subList method returns a view of the list, modifications done by Collections.sort will affect the backing list as well.

提交回复
热议问题