title: Get unique indexes after sorting an array with duplicate entries
body: <p>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. <code>[1,1,1,2,2,]</code>, then indexes are the same for these entries. For the example <code>[3,5,5,3,3,]</code> the indexes would be <code>[0,1,1,0,0]</code>. But I would need to get the following indexes <code>[0,3,4,1,2]</code>. How to do this?</p>
  
  <pre><code>ArrayList&lt;Double&gt; nfit = new ArrayList&lt;Double&gt;();
  ArrayList&lt;Double&gt; nfit_copy = new ArrayList&lt;Double&gt;(nfit);
  
  // Fill nfit
  
  Collections.sort(nfit);
  
  int[] ind = new int[nfit.size()];
  
  for (int n = 0; n &lt; nfit.size(); n++){
      ind[n] = nfit_copy.indexOf(nfit.get(n));
  }
  </code></pre>