Here you can find the source of sortIndexes(final T[] array)
public static <T extends Comparable<T>> Integer[] sortIndexes(final T[] array)
//package com.java2s; //License from project: Apache License import java.util.Arrays; import java.util.Comparator; public class Main { public static <T extends Comparable<T>> Integer[] sortIndexes(final T[] array) { Integer[] idx = new Integer[array.length]; for (int i = 0; i < array.length; i++) idx[i] = i;// w w w . j a v a 2 s . c o m Arrays.sort(idx, new Comparator<Integer>() { public int compare(final Integer o1, final Integer o2) { return array[o1].compareTo(array[o2]); } }); return idx; } /** * Similar to the "order" function in R. Returns the indices of the sorted array. * @param array Array whose order is calculated * @return Array of indices for the ordered vector. The first index is the minimum value, and so forth. */ public static Integer[] sortIndexes(final float[] array) { Integer[] idx = new Integer[array.length]; for (int i = 0; i < array.length; i++) idx[i] = i; Arrays.sort(idx, new Comparator<Integer>() { public int compare(final Integer o1, final Integer o2) { return Float.compare(array[o1], array[o2]); } }); return idx; } }