List of utility methods to do Array Sort
String[] | sortNames(String[] names) sort Names String[] newOrder = new String[] { "labelx", "labels1", "labels2", "labels3" }; String[] sortedNames = new String[names.length]; int index = 0; for (String newOrderName : newOrder) { for (String name : names) { if (name.equals(newOrderName)) { sortedNames[index++] = name; return sortedNames; |
String[] | sortNames(String[] names) Sorts the given array alphabetically. if (names == null || names.length == 0 || names[0] == null) { return names; String[] copy = new String[names.length]; System.arraycopy(names, 0, copy, 0, names.length); Arrays.sort(copy); return copy; |
Object[] | sortNullElements(Object[] array) Move all null elements to end of array. if (array == null) { return null; if (array.length == 0) { return array; Object[] tmp = new Object[array.length]; int k = 0; ... |
int[] | sortPerm(final int[] w) sort Perm Integer[] perm = new Integer[w.length]; for (int i = 0; i < perm.length; i++) { perm[i] = i; Arrays.sort(perm, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return w[o1] - w[o2]; }); int[] res = new int[w.length]; for (int i = 0; i < perm.length; i++) { res[i] = perm[i]; return res; |
Integer[] | sortPermutation(final int[] A) sort Permutation class comparator implements Comparator<Integer> { public int compare(Integer a, Integer b) { if (A[a.intValue()] < A[b.intValue()]) { return -1; if (A[a.intValue()] == A[b.intValue()]) { return 0; if (A[a.intValue()] > A[b.intValue()]) { return 1; return 0; Integer[] permutation = new Integer[A.length]; for (int i = 0; i < A.length; i++) { permutation[i] = i; Arrays.sort(permutation, new comparator()); return permutation; |
double[][] | sortPixels(double[] data, int numPixel) Return a 2D array int roi = data.length / numPixel; double[][] pixels = new double[numPixel][roi]; for (int pix = 0; pix < numPixel; pix++) { for (int slice = 0; slice < roi; slice++) { int pixId = pix * roi + slice; double value = data[pixId]; pixels[pix][slice] = value; return pixels; |
Integer[] | sortPopup(Integer[] integers) popup sorting (assent) Integer[] sortedIntegers = new Integer[integers.length]; System.arraycopy(integers, 0, sortedIntegers, 0, integers.length); int arrayLength = sortedIntegers.length; for (int i = 0; i < arrayLength - 1; i++) { int a = sortedIntegers[i]; for (int j = i + 1; j < arrayLength; j++) { int b = sortedIntegers[j]; if (a > b) { ... |
int[] | sortRetain(long[] a) Sorts the specified array of longs into ascending numerical order. int[] pos = getPosArray(a.length); sort1(a, pos, 0, a.length); return pos; |
void | sortReverseOrder(String[] strings) Sorts an array of strings in place using quicksort in reverse alphabetical order. if (strings.length > 1)
quickSortReverse(strings, 0, strings.length - 1);
|
String[] | sortStringArray(String array[], boolean inplace) Sort the given String array in place. String tosort[] = array; if (!inplace) { tosort = new String[array.length]; System.arraycopy(array, 0, tosort, 0, array.length); quickSortStringArray(tosort, 0, tosort.length - 1); return tosort; |