I declared List<Integer[]> results = new ArrayList<>(); in java 8.
And result = [[-6, 1, 5],[-8, 2, 6],[-8, 3, 5]]. I want to sort the result to this result = [[-8, 2, 6], [-8, 3, 5], [-6, 1, 5]]. How can i do it in java?
I implemented Collections.sort(result, (o1,o2)-> {(o1.get(0) > o2.get(0)) ? 1 : (o1.get(0) < o2.get(0) ? -1 : 0)};);
but this code snippet is causing an error.
As per your question, if you just need it sorted based on the first value then I think the following code should work for you :
The output is :