You have two basic options provided by java.util.Collections
:
<T extends Comparable<? super T>> void sort(List<T> list)
T implements Comparable
and you're fine with that natural ordering<T> void sort(List<T> list, Comparator<? super T> c)
Comparator
.Depending on what the Collection
is, you can also look at SortedSet
or SortedMap
.