Search
 
SCRIPT & CODE EXAMPLE
 

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));
    }
}
Comment

arrays.sort with comparator

Arrays.sort(twoDim, new Comparator<int[]>() {
    @Override
    public int compare(int[] o1, int[] o2) {
        return ((Integer) o2[0]).compareTo(o1[0]);
    }
});
Comment

arrays.sort with comparator

Arrays.sort(twoDim, new Comparator<int[]>() {
    @Override
    public int compare(int[] o1, int[] o2) {
        return Integer.compare(o2[0], o1[0]);
    }
});
Comment

PREVIOUS NEXT
Code Example
Java :: how to get input of local date type java 
Java :: -3 to string in java 
Java :: get spring application context 
Java :: binary search java 
Java :: how to name loops in java 
Java :: reversing the linked list 
Java :: comparacion de strings java 
Java :: argumentcaptor java mockito 
Java :: sort 2d array based on one column java 
Java :: print a list java 
Java :: jasypt-spring-boot 
Java :: insert data from database sqlite android 
Java :: how to convert string to int in java 
Java :: codepointat java 
Java :: loop array using stream java 
Java :: Float to bytes java 
Java :: Java LogManager 
Java :: copy linked list 
Java :: creating an array list in java 
Java :: how to make a text field required in android studio 
Java :: How to merge two sorted arrays? 
Java :: maximum integer in array java 
Java :: erstelle hashmap java 
Java :: Stop gninnipS My sdroW! javascrip codewars 
Java :: how to return the first character in an array from a method java 
Java :: potenzieren java 
Java :: android java how to stop activity from opening twice programatically 
Java :: javac encoding utf-8 
Java :: how to disable the cors in spring boot 
Java :: onclick listview javafx 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =