Reverse sort a 2d double array by row on the column given by index. - Java Collection Framework

Java examples for Collection Framework:Array Sort

Description

Reverse sort a 2d double array by row on the column given by index.

Demo Code


//package com.java2s;

public class Main {
    /**//from   w  w w .  j a v a2s  .  c o m
     * Reverse sort a 2d array by row on the column given by index.
     * Helper method for sortedMemberStats().
     */
    public static void sort2DArray(double[][] array, final int index) {
        java.util.Arrays.sort(array, new java.util.Comparator<double[]>() {
            public int compare(double[] a, double[] b) {
                return -1 * Double.compare(a[index], b[index]);
            }
        });
    }
}

Related Tutorials