I have a 2D array as an input of NxM size, where N is known and static, and M actually grows dynamically and will be different for each index of the array[0...N-1].
I was thinking I could initialize my 2D array like so:
ArrayList<Integer>[] array = new ArrayList[n];
but this leaves all sub-arrays initialized to null instead of an ArrayList instance. For example, calling
array[0].add(1);
crashes with a NullPointerException
How do I properly initialize the ArrayLists?