Java Utililty Methods List Sort

List of utility methods to do List Sort

Description

The list of methods to do List Sort are organized into topic(s).

Method

Listsorted(List l, Comparator comparator)
Return a copy of the list sorted according to the given comparator
List<T> copy = new ArrayList<T>(l);
Collections.sort(copy, comparator);
return copy;
Listsorted(List l)
Sort the given list and return a reference to it
Collections.sort(l);
return l;
ListsortedArray(List list)
sorted Array
return Arrays.asList(sortedArray(list.toArray()));
voidsortedInsert(List list, E e, Comparator c)
Inserts an element into a sorted list
assert isSorted(list, c);
int index = Collections.binarySearch(list, e, c);
if (index >= 0)
    ((List<E>) list).add(index, e);
else
    ((List<E>) list).add(-index - 1, e);
assert isSorted(list, c) : list;
intsortedInsert(List list, T item, Comparator comparator)
Inserts the given item into the specified sorted list at the correct position given its sort order
int insertIndex = Collections.binarySearch(list, item, comparator);
if (insertIndex < 0) 
    insertIndex = -(insertIndex + 1);
list.add(insertIndex, item);
return insertIndex;
ListsortedList(List list)
Returns a sorted version of the given list
if (list == null || list.size() <= 1) {
    return list;
ArrayList<T> ret = new ArrayList<>();
ret.addAll(list);
Collections.sort(ret);
return ret;
ListsortedUnion(List args1, List args2)
sorted Union
SortedSet set = new TreeSet();
set.addAll(args1);
set.addAll(args2);
List lst = new ArrayList(set.size());
for (Iterator it = set.iterator(); it.hasNext();) {
    Object o = it.next();
    lst.add(o);
return lst;
List>sortEntrySetToList(Set> set)
sort Entry Set To List
List<Entry<Long, Long>> list = new LinkedList<Map.Entry<Long, Long>>(set);
Collections.sort(list, new Comparator<Entry<Long, Long>>() {
    @Override
    public int compare(Entry<Long, Long> o1, Entry<Long, Long> o2) {
        if (o1.getValue() > o2.getValue())
            return 1;
        if (o1.getValue() < o2.getValue())
            return -1;
...
voidsortIds(List ids)
Sorts the list of IDs.
Collections.sort(ids);
voidsortIfUnsorted(List genomes)
sort If Unsorted
int previous = Integer.MIN_VALUE;
for (int i = 0; i < genomes.size(); i++) {
    if (genomes.get(i) < previous) {
        genomes.sort(null);
        return;
    previous = genomes.get(i);