Arrays.sort(people, (n1, n2) -> (n2[0] == n1[0])? n1[1] - n2[1] : n2[0] - n1[0]);
or
Arrays.sort(people,new Comparator<int[]>(){
@Override
public int compare(int[] n1, int[] n2){
return (n2[0] == n1[0])? n1[1] - n2[1]: n2[0] - n1[0];
}
});
Both these perform the same operation.
Input: [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]
Output: [[7,0],[7,1],[6,1],[5,0],[5,2],[4,4]]
I know the code is sorting it in groups but I don't understand how. I was similarly confused about PriorityQueue in Java:
PriorityQueue<Integer> pq = new PriorityQueue<>((a, b)-> b - a);
This one sorts in decreasing order.
Can someone explain it? Where can I study or read more about these "overrides" if there is any such material?