Here you can find the source of sortIndex(double[] doubleArray)
public static int[] sortIndex(double[] doubleArray)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; public class Main { public static int[] sortIndex(double[] doubleArray) { // Get the index of a sorted double array return sortIndex(_arrayToArrayList(doubleArray)); }//from w w w .j a va 2s .c o m public static int[] sortIndex(ArrayList<Double> doubleArrayList) { // Get the index of a sorted Double ArrayList ArrayList<Double> sortedArrayList = new ArrayList<Double>(doubleArrayList); Collections.sort(sortedArrayList); ArrayList<Double> copyArrayList = new ArrayList<Double>(doubleArrayList); int length = sortedArrayList.size(); int[] sortedIndices = new int[length]; Arrays.fill(sortedIndices, -1); for (int i = 0; i < length; i++) { // Traverse the value in descending value Double ithValue = sortedArrayList.get(length - 1 - i); while (_contains(sortedIndices, copyArrayList.indexOf(ithValue))) { copyArrayList.set(copyArrayList.indexOf(ithValue), -1.); } sortedIndices[i] = copyArrayList.indexOf(ithValue); } return sortedIndices; } private static ArrayList<Double> _arrayToArrayList(double[] doubleArray) { ArrayList<Double> doubleArrayList = new ArrayList<Double>(); for (int i = 0; i < doubleArray.length; i++) { doubleArrayList.add(doubleArray[i]); } return doubleArrayList; } private static boolean _contains(int[] intArray, int val) { for (int intVal : intArray) { if (intVal == val) { return true; } } return false; } }