I have a 2D matrix of size nXm for which each cell contains an unknown number of values of type Integer(therefore I have to use a List to be able to dynamically add stuff, and have to use a 2D array nXm because arrays are easy to access and write code). Pl
- ease before recommend me any other data structure answer my question below and then discuss why I should not this and go for what you think will work better and more efficient:
How can I allocate memory to the variable below?
ArrayList<Integer>[][] i2DArrayList;
I know at some points I have to do this. However prior to that I have to do some other memory allocation that I don't remember know. Could you guide me in this matter.
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
i2DArrayList[i][j] = new ArrayList<Integer>();
}
}
I already know how to do it in 1D:
ArrayList<Integer>[] i1DArrayList;
i1DArrayList = new ArrayList[n];
for (int i = 0; i < i1DArrayList.length; i++) {
i1DArrayList[i] = new ArrayList<Integer>();
}