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

int[]ListToSortedArray(List list)
Convert a List of Integer s to a sorted array of ints.
if (list == null) {
    return null;
int count = list.size();
int[] result = new int[count];
int last = Integer.MIN_VALUE;
boolean needsSorting = false;
for (int i = 0; i < count; ++i) {
...
LinkedList>mapTosortedScoreList(HashMap unSortedMap)
This function creates a sorted list using the maps
LinkedList<Entry<Long, Double>> mapList = new LinkedList<Entry<Long, Double>>(unSortedMap.entrySet());
Collections.sort(mapList, new Comparator<Entry<Long, Double>>() {
    @Override
    public int compare(Entry<Long, Double> o1, Entry<Long, Double> o2) {
        return o2.getValue().compareTo(o1.getValue());
});
return mapList;
...
Doublemaximum(List sortedDataAscendingOrder)
Get the maximum value thru linear interpolations
return interpolateLinearlyQuantile(sortedDataAscendingOrder, (double) 1);
ListmergeLong(List l1, List l2, boolean sort)
merge Long
Set<Long> set = new HashSet<Long>(l1);
set.addAll(l2);
List<Long> res = new ArrayList<Long>(set);
if (sort) {
    Collections.sort(res);
return res;
ListmergeSort(List m)
To sort a given List of values.
Sorting algorithm: MergeSort.
Operates: Recursively.
More information: http://en.wikipedia.org/wiki/Merge_sort
if (m.size() <= 1) {
    return m;
int middle = m.size() / 2;
List<E> left = m.subList(0, middle);
List<E> right = m.subList(middle, m.size());
right = mergeSort(right);
left = mergeSort(left);
...
ListmergeSort(List list)
MergeSorts the given list.
if (list.size() <= 1) {
    return list;
} else {
    int half = list.size() / 2;
    List<K> left = mergeSort(subList(list, 0, half - 1));
    List<K> right = mergeSort(subList(list, half, list.size() - 1));
    return merge(left, right);
voidmergeSortedLists(List dest, List[] src, boolean removeDuplicates)
Merge two sorted Lists I could have used the Java Set collection here...unfortunately the only ordered set is their TreeSet, and set union/subtraction therefore take NlogN with a pretty big constant overhead.
int numSrc = 0;
for (int i = 0; i < src.length; i++) {
    if (src[i] != null) {
        numSrc++;
if (numSrc == 1) {
    for (int i = 0; i < src.length; i++) {
...
voidquickSort(Comparable[] list, int min, int max)
Performs a quick sort on the given array of Comparable objects between the min and maximum range.
Arrays.sort(list, min, max + 1);
booleanremoveSortByColumnName(List sortProperty, List ascending, String columnName)
remove Sort By Column Name
if (sortProperty == null) {
    return false;
int index = -1;
for (int i = 0, size = sortProperty.size(); i < size; i++) {
    String sort = sortProperty.get(i);
    if (sort.equals(columnName)) {
        index = i;
...
voidremoveSortColumns(List selectColumns, List sorts, List ascending)
remove Sort Columns
List<String> removedSorts = new ArrayList<String>();
for (String sort : sorts) {
    if (!selectColumns.contains(sort)) {
        removedSorts.add(sort);
for (String sort : removedSorts) {
    removeSortByColumnName(sorts, ascending, sort);
...