I need to sort an array and get indexes linked to an unsorted array. The problem is that if the unsorted array contains duplicate entries, i.e. [1,1,1,2,2,], then indexes are the same for these entries. For the example [3,5,5,3,3,] the indexes would be [0,1,1,0,0]. But I would need to get the following indexes [0,3,4,1,2]. How to do this?
ArrayList<Double> nfit = new ArrayList<Double>();
ArrayList<Double> nfit_copy = new ArrayList<Double>(nfit);
// Fill nfit
Collections.sort(nfit);
int[] ind = new int[nfit.size()];
for (int n = 0; n < nfit.size(); n++){
ind[n] = nfit_copy.indexOf(nfit.get(n));
}