You can create an array of ArrayList elements because your line count is fixed.
ArrayList[] dynamicArray = new ArrayList[n]();
Note. You will need to allocate an ArrayList object in each array entry. So that...
for (int loop = 0; loop < n; loop++) dynamicArray[loop] = new ArrayList();
OR, if you want both rows and columns to be dynamic, you could create an ArrayList from ArrayLists ....
ArrayList<ArrayList<T>> dynamicArray = new ArrayList<ArrayList<T>>();
Once again, you need to create a list of arrays in each new entry in dynamicArray.
source share