fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int[][] arr = {{1,3},{1,2},{7,8},{8,10}};
  14. // for(int[] i : arr){
  15. // System.out.println(i[0] + " " + i[1]);
  16. // }
  17.  
  18. Arrays.sort(arr,(a,b)->{
  19. // if(a[0]<b[0])
  20. // return -1;
  21. // else if(a[0]>b[0])
  22. // return 1;
  23. // else{
  24. // if(a[1]<b[1])
  25. // return -1;
  26. // else if(a[1]>b[1])
  27. // return 1;
  28. // else
  29. // return 0;
  30. // }
  31. if(Integer.compare(a[0],b[0]) == 0){
  32. return Integer.compare(a[1],b[1]);
  33. } else {
  34. return Integer.compare(a[0],b[0]);
  35. }
  36. });
  37.  
  38. for(int[] i : arr){
  39. System.out.println(i[0] + " " + i[1]);
  40. }
  41. }
  42. }
Success #stdin #stdout 0.13s 50240KB
stdin
Standard input is empty
stdout
1 2
1 3
7 8
8 10