You could do this by adding pairs of Long to a TreeMap, where the key is values[index] and the value is index.
traversing the map's iterator will yield the sortindex values.
update
Seeing that there is no accepted answer, here is the code resulting from following up the comments to this answer.
long[] values = { 1 , 3 , 2 , 5 , 4 };
int[] output = new int[values.length];
Map<Long, Integer> map = new TreeMap<Long, Integer>();
for (int n = 0; n < values.length; n++) {
map.put(values[n] * values.length + n, n);
}
int n = 0;
for (Integer index: map.values()) {
output[n++] = index;
}
System.out.println(Arrays.toString(output));
Output:
[0, 2, 1, 4, 3]
the solution also works when duplicates are part of the input:
long[] values = { 8, 5, 3, 2, 1, 1 };
Output:
[4, 5, 3, 2, 1, 0]
If it is permissible to receive the sortOrder array as an Integer array, the second loop can be replaced by:
Integer[] output = map.values().toArray(new Integer[values.length]);