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 I want to sort this list from index 1 till last index.
One way As I think that I can create a sub-list from main list with desired index range, sort it and add the sub-list accordingly. But my question is:
Is there any API already available for that? Or any other faster way to achieve this.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With