'sort 2D int array JAVA
I have one 2 dimensional array It's an array with 7 int in line and more lines.
int[][] new arr=new[7][100];
number in line is ranked.
I need a ranked array.
for example
9 4 15 22 32 47 50
1 5 9 12 19 25 36
22 23 25 29 36 55 99
1 5 11 12 19 25 36
after sort
1 5 9 12 19 25 36
1 5 11 12 19 25 36
9 4 15 22 32 47 50
22 23 25 29 36 55 99
Solution 1:[1]
I would do something like this,or something similar:
I saw something similar in Stack Overflow: https://stackoverflow.com/a/15452462/8024829.
double[][] array= {
{1, 5},
{13, 1.55},
{12, 100.6},
{12.1, .85} };
java.util.Arrays.sort(array, new java.util.Comparator<double[]>() {
public int compare(double[] a, double[] b) {
return Double.compare(a[0], b[0]);
}
});
Solution 2:[2]
You can try this simple expression:
Arrays.sort(A, (a, b) -> a[0] - b[0]);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oron Zimmer |
| Solution 2 | Joe |
