What is the role of a pair of double brackets ([][]
) in Java?
reference code(Leetcode 1351. Count Negative Numbers in a Sorted Matrix):
class Solution {
public int countNegatives(int[][] grid) {
final int m = grid.length;
final int n = grid[0].length;
int ans = 0;
int i = m - 1;
int j = 0;
while (i >= 0 && j < n) {
if (grid[i][j] < 0) {
ans += n - j;
--i;
} else {
++j;
}
}
return ans;
}
}
I tried finding about it on google but was not able to find anything regarding this. Please tell me why we use a double bracket here?