I have List of Double Array and I would like sort it according to first and last field. So far I am able to sort it by only 1 element of array.
Real state:
0 1 2
------- ------- -------
78 100 0
78 100 1
0 100 0
104 100 1
Expected:
0 1 2
------- ------- -------
0 100 0
78 100 1
78 100 0
101 100 1
I want to sort field according to value of 1st element of Array. If value of 1st and 2nd are equal I want to sort according to 3rd element where first should be 1 and then 0 (there will be only 1 and 0 value)
List<Double[]> splitList = new ArrayList<>();
Double[] tmp1 = { 78d, 100d, 0d };
Double[] tmp2 = { 78d, 100d, 1d };
Double[] tmp3 = { 0d, 100d, 0d };
Double[] tmp4 = { 104d, 100d, 1d };
splitList.add(tmp1);
splitList.add(tmp2);
splitList.add(tmp3);
splitList.add(tmp4);
splitList.sort(Comparator.comparingDouble(a -> a[0]));
This one sort me according to first element. I found solution to sort by two elements https://stackoverflow.com/a/26865122/9774735 so I tried it:
splitList.sort(Comparator.comparingDouble(a -> a[0]).thenComparingDouble(b -> b[2]));
and it output me an error:
Multiple markers at this line
- The type of the expression must be an array type but it resolved
to Object
- The type of the expression must be an array type but it resolved
How can I compare List of Array?