On my quest learning Java I come across one doubt.
For sorting a unidimensional array we can use Arrays.sort() but if I want to sort a bidimensional array based on three columns? Is there any option to d that or do I have to code it for my self (something like three nested loops)?
Here is an example input:
13 2 28 36
1 4 56 17
4 2 5 40
2 4 41 55
9 5 48 12
19 2 25 12
20 5 13 8
15 3 51 30
12 5 39 59
17 3 56 40
3 1 56 46
7 3 28 51
8 5 14 58
5 3 34 15
14 4 53 2
18 4 38 57
6 2 16 25
16 3 17 13
10 5 41 33
11 1 13 57
Columns are int and this is stored in an array of ints.
I wanna sort by column 2, if equal numbers are found, then sort by column 3 and finally, if equals found, sort by column 3.
The output should be this:
11 1 13 57
3 1 56 46
4 2 5 40
6 2 16 25
19 2 25 12
13 2 28 36
16 3 17 13
7 3 28 51
5 3 34 15
15 3 51 30
17 3 56 40
18 4 38 57
2 4 41 55
14 4 53 2
1 4 56 17
20 5 13 8
8 5 14 58
12 5 39 59
10 5 41 33
9 5 48 12
Is there a simple way for doing this? Remember that I'm new at Java.
regards,
Favolas