Sorting a part of Java ArrayList
use the subList
[inherited from AbstractList
] method in ArrayList
. And then use Collections.sort()
on that sub-list. That is if writing a highly optimised custom sort function is truly hard work.
Collections.sort(list.subList(0,3));
Note: '3' here is excluded from sorting
It is described in the documentation:
public List subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.