Initialize List in Java

Total
0
Shares

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?


Solution

Use

List<List<Integer>> list = new ArrayList<List<Integer>>();

or since Java 1.7

List<List<Integer>> list = new ArrayList<>();

Source: StackOverflow.com

Leave a Reply

Your email address will not be published. Required fields are marked *