【发布时间】:2013-04-12 19:24:35
【问题描述】:
我需要对数组进行排序并获取链接到未排序数组的索引。问题是如果未排序的数组包含重复的条目,即[1,1,1,2,2,],那么这些条目的索引是相同的。对于示例[3,5,5,3,3,],索引将是[0,1,1,0,0]。但我需要获得以下索引[0,3,4,1,2]。如何做到这一点?
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));
}
【问题讨论】: