For arrays there is a special function for sorting a part of the array from index to index:
Arrays.sort(Object[] a, int fromIndex, int toIndex)
For List< T>
there is also a function for sorting
Collections.sort(List<T> list)
Unluckily there is no variant accepting a fromIndex and toIndex parameter.
I know that I could solve this problem by either applying
- Convert the List into an array and apply
Arrays.sort, then convert it back to a List - Copying the list entries indexed by fromIndex to toIndex to a new List (by using
list.subList(fromIndex, toIndex)), sort it and overwrite the old list entries
But I hope there is a prettier way to do that.