I've been working on a school project that requires (or at least strongly suggests) using two dimensional ArrayLists in Java (specifically an ArrayList that holds ArrayList of ints). I don't find the syntax too hard to grasp, but the below code has really stumped me:
List<ArrayList<Integer>> arrList2D = new ArrayList<>();
List<Integer> arrList1D = new ArrayList<>();
arrList1D.add(1);
arrList2D.add(arrList1D);
That snippet gives me the error:
Cannot convert List<Integer> to ArrayList<Integer>
on the very last line. What I find confusing is that I explicitly instantiate arrList1D as an ArrayList. Is there something obvious I'm missing? Would definitely appreciate any help with this. Sorry for any redundant questions.
List<List<Integer>> arrList2D = new ArrayList<>();