What is the most efficient way of sorting only a part of ArrayList?
Say all elements from index 0 to 3 in an Arraylist which contains 10 elements.
Is there a library function available in Java?
Apart from Collections.sort(list) which sorts the entire List!
Writing a highly optimised custom sort function will take some work.
In Java 8+, use
List#sort.In earlier Java:
Note: ‘3’ here is excluded from sorting.
To quote the documentation: