You only set the capacity of the external / internal ArrayLists. They are still empty.
And your loop is not even executed, because it a.size()is 0.
You will need a second inner loop to add elements to them.
ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>(5);
for (int i = 0; i < 5 ; i++) {
List<Integer> lst = new ArrayList<Integer>(10);
for (int j = 0; j < 10; j++) {
lst.add(j);
}
a.add(lst);
}
System.out.println(a.get(a.size()-1).get(9));
Edit: And follow up a.set(i, ...). It throws an exception if I> = a.size ().
source
share