How can I initialize List<List<Integer>>
in Java?
I know List
is an interface and I can use ArrayList
or LinkedList
to implement List<Integer> list = new ArrayList<Integer>()
, but when I initialize List<List<Integer>> list = new ArrayList<ArrayList<Integer>>();
I get error incompatible types:
ArrayList<ArrayList<Integer>> cannot be converted to List<List<Integer>>.
So how can I proceed?
Advertisement
Answer
Use
List<List<Integer>> list = new ArrayList<List<Integer>>();
or since Java 1.7
List<List<Integer>> list = new ArrayList<>();