Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> Integer[] getSortedArrayIndexes(final T[] array, final Comparator<T> comparator) { Integer[] indexes = new Integer[array.length]; for (int i = 0; i < indexes.length; i++) { indexes[i] = i; } if (comparator != null) { Arrays.sort(indexes, new Comparator<Integer>() { @Override public int compare(Integer aIndex, Integer bIndex) { return comparator.compare(array[aIndex], array[bIndex]); } }); } return indexes; } public static <T extends Comparable> Integer[] getSortedArrayIndexes(final T[] array) { Integer[] indexes = new Integer[array.length]; for (int i = 0; i < indexes.length; i++) { indexes[i] = i; } Arrays.sort(indexes, new Comparator<Integer>() { @Override public int compare(Integer aIndex, Integer bIndex) { return array[aIndex].compareTo(array[bIndex]); } }); return indexes; } }