What is the equivalent in Java to this in Python?
array_name = [0 for i in range(5)]
Specifically, I want to create a 2 dimensional Java ArrayList and initialize each value as 0. This is what I was thinking, in semi-psuedocode, following Python, but it obviously doesn't work:
ArrayList<ArrayList<Integer>> grid = new ArrayList<ArrayList<Integer>>() {{
(add(Arrays.asList(0 for i : ROWS) for j : COLUMNS);
}};
Where ROWS and COLUMNS are constants defined elsewhere. In the end, I want a 2D ArrayList, with sizes given by the ROWS and COLUMNS constants, and each value initialized as 0. Is there a way to do this?
And ArrayLists don't allow primitive types as the generic type (like the primitive int). Then having the reference type doesn't have a default of 0 since it is an object. So any other questions concerning the initialization of an array to 0 that have to do with the primitive int don't answer mine.