Here you can find the source of deltaMetricToSortedIndicies( final double[][] deltaMetric)
public static <TK, FV> int[][] deltaMetricToSortedIndicies( final double[][] deltaMetric)
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static <TK, FV> int[][] deltaMetricToSortedIndicies( final double[][] deltaMetric) { class DeltaIndex implements Comparable<DeltaIndex> { public int i, j; public DeltaIndex(int i, int j) { this.i = i; this.j = j; }// w w w.j ava 2 s . co m @Override public int compareTo(DeltaIndex o) { double diff = deltaMetric[i][j] - deltaMetric[o.i][o.j]; if (diff < 0) return -1; else if (diff > 0) return 1; else return 0; } } ; int[][] indices = new int[deltaMetric.length][]; for (int i = 0; i < indices.length; i++) { indices[i] = new int[deltaMetric[i].length]; List<DeltaIndex> sortList = new ArrayList<DeltaIndex>( indices[i].length); for (int j = 0; j < indices[i].length; j++) { sortList.add(new DeltaIndex(i, j)); } Collections.sort(sortList); for (int j = 0; j < indices[i].length; j++) { indices[i][j] = sortList.get(j).j; } } return indices; } }