Java Utililty Methods Array Sort

List of utility methods to do Array Sort

Description

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

Method

voidsort(int[] intValues)
sort
int idxs[] = intValues;
int length = idxs.length;
for (int gap = length / 2; gap > 0; gap /= 2) {
    for (int i = gap; i < length; i++) {
        for (int j = i - gap; j >= 0; j -= gap) {
            if (idxs[j] > idxs[j + gap]) {
                int swap = idxs[j];
                idxs[j] = idxs[j + gap];
...
voidsort(int[] keys, int[] values)
Sorts the keys in an increasing order.
hybridsort(keys, values, 0, keys.length - 1);
voidsort(int[] values)
Sorts an interger array.
int length = values.length;
if (length > 1) {
    for (int i = 0; i < (length - 1); i++) {
        for (int j = i + 1; j < length; j++) {
            if (values[j] < values[i]) {
                int temp = values[i];
                values[i] = values[j];
                values[j] = temp;
...
Number[]sort(Number[] array)
Returns a sorted copy of the array (ascending).
return sort(array, true);
O[]sort(O[] array)
Sorts the given array by its natural order of objects and then returns it, assuming the natural order of the elements follows the Comparable contract.
Arrays.sort(array);
return array;
voidsort(Object[] a)
sort
Arrays.sort(a);
voidsort(Object[] arr, int start, int end)
sort
if (end - start <= 2) {
    if (end - start == 2 && arr[start].toString().compareTo(arr[start + 1].toString()) > 0) {
        Object tmp = arr[start];
        arr[start] = arr[start + 1];
        arr[start + 1] = tmp;
    return;
if (end - start == 3) {
    sort(arr, start, start + 2);
    sort(arr, start + 1, start + 3);
    sort(arr, start, start + 2);
    return;
int middle = (start + end) / 2;
sort(arr, start, middle);
sort(arr, middle, end);
Object[] tmp = new Object[end - start];
int i0 = start;
int i1 = middle;
for (int i = 0; i < tmp.length; i++) {
    if (i0 == middle) {
        tmp[i] = arr[i1++];
    } else if (i1 == end || arr[i0].toString().compareTo(arr[i1].toString()) < 0) {
        tmp[i] = arr[i0++];
    } else {
        tmp[i] = arr[i1++];
System.arraycopy(tmp, 0, arr, start, tmp.length);
voidsort(Object[] array)
Performs a quicksort of the given objects by their string representation in ascending order.
qsort(array, 0, array.length - 1);
voidsort(Object[] array, Comparator comparator)
sort
sort(array, array.length, comparator);
voidsort(Object[] array, int start, int end)
Sorts the specified range in the array in ascending order.
int middle = (start + end) / 2;
if (start + 1 < middle)
    sort(array, start, middle);
if (middle + 1 < end)
    sort(array, middle, end);
if (start + 1 >= end)
    return; 
if (((Comparable<Object>) array[middle - 1]).compareTo(array[middle]) <= 0)
...