Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

arrays.sort with comparator

import java.util.*;

public class Test {

    public static void main(String args[]) {

        int[][] twoDim = { {1, 2}, {3, 7}, {8, 9}, {4, 2}, {5, 3} };

        Arrays.sort(twoDim, Comparator.comparingInt(a -> a[0])
                                      .reversed());

        System.out.println(Arrays.deepToString(twoDim));
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #comparator
ADD COMMENT
Topic
Name
3+6 =