Copy the ArrayList and do the sort, then use indexOf.
ArrayList<Double> nfit = new ArrayList<Double>(); nfit.add(2.0); nfit.add(5.0); nfit.add(1.0); nfit.add(8.0); nfit.add(3.0); ArrayList<Double> nstore = new ArrayList<Double>(nfit);
If you need indexes in an ArrayList,
Collections.sort(nstore); for (int n = 0; n < nfit.size(); nfit++){ nstore.add(n, nfit.indexOf(nstore.remove(n))); } Collections.sort(nfit);
This will result in one sorted ArrayList nfit and one ArrayList of nstore indices.
source share