Nitish Upreti Nitish Upreti - 5 months ago 9
Java Question

Sorting a part of Java ArrayList

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.

Answer
Collections.sort(list.subList(0,3));