This Lambda 8 method came up in one of the suggested answers on leetcode.com: https://leetcode.com/problems/merge-intervals/discuss/21222/A-simple-Java-solution
Below is the method I cannot seem to understand:
int[][] intervals = {{8,10}, {1,3},{2,6},{15,18}};
Arrays.sort(intervals, (i1, i2) -> Integer.compare(i1[0], i2[0]));
I understand that the Arrays.sort() sorts the array in ascending order and the second argument is supposed to be the range it sorts the array.
What I don't understand is the i1 and i2 arguments and the Integer.compare() method that follows.
What exactly are i1 and i2 here? Are they arrays or the integers?
How come we don't write (int i1, int i2)? Is this because we have already mentioned Integer afterward?
(int[] i1, int[] i2)but it's not necessary because the compiler assumes that the comparator for sorting anint[][]will beComparator<int[]>.