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

double[]sortToFXYSumOrder(final double[] coeffs)
sort To FXY Sum Order
final double[] newOrder = new double[coeffs.length];
newOrder[0] = coeffs[0];
newOrder[1] = coeffs[1];
newOrder[2] = coeffs[2];
newOrder[3] = coeffs[4];
newOrder[4] = coeffs[3];
newOrder[5] = coeffs[5];
newOrder[6] = coeffs[8];
...
voidsortTwoArrays(A[] firstArray, B[] secondArray)
Utility method to sort two related arrays - that is, two arrays where the elements are related to each other by their position in the array.
if (firstArray.length != secondArray.length) {
    throw new RuntimeException("Both arrays must be of the same length");
class element {
    public A first;
    public B second;
element[] elements = new element[firstArray.length];
...
voidsortWith(final int[] ary, int[] ary2)
Sort two arrays - the second one is sorted according the first one.
Integer[] sortOrder = new Integer[ary.length];
for (int i = 0; i < sortOrder.length; i++)
    sortOrder[i] = i;
Arrays.sort(sortOrder, new Comparator<Integer>() {
    @Override
    public int compare(Integer o1, Integer o2) {
        return ary[o1] - ary[o2];
});
sortAccording2(ary, sortOrder);
sortAccording2(ary2, sortOrder);
voidSortWithIndex(double[] arr, Integer[] i)
Sort With Index
final Integer[] idx = i;
final double[] data = arr;
Arrays.sort(idx, new Comparator<Integer>() {
    @Override
    public int compare(final Integer o1, final Integer o2) {
        return Double.compare(data[o1], data[o2]);
});
...
int[]sortWithInds(int[] x, int[] idx)
sort With Inds
int[] out = x.clone();
Arrays.sort(out);
for (int i = 0; i < out.length; i++)
    idx[i] = indexOf(out[i], x);
return out;
int[]sortWithNoMissingValues( double[] array)
Sorts a given array of doubles in ascending order and returns an array of integers with the positions of the elements of the original array in the sorted array.
int[] index = initialIndex(array.length);
if (array.length > 1) {
    quickSort(array, index, 0, array.length - 1);
return index;
Object[]toSortedArray(Collection collection)
to Sorted Array
Object[] result = collection.toArray();
Arrays.sort(result);
return result;
String[]toSortedArray(Set groups)
Alphabetically sort the list of groups
String[] sortedArray = groups.toArray(new String[groups.size()]);
Arrays.sort(sortedArray);
return sortedArray;
int[]toSortedIntArray(Collection ints)
to Sorted Int Array
int[] result = toIntArray(ints);
Arrays.sort(result);
return result;
String[]toStringArray(Collection collection, boolean sort)
to String Array
if (collection == null)
    return null;
String[] array = new String[collection.size()];
int i = 0;
for (Object o : collection)
    array[i++] = o.toString();
if (sort)
    Arrays.sort(array);
...