This return value is encountered on Leetcode
Public class Solution { public list<list<integer>> levelorder (TreeNode root) { }}
List<list<integer>>
That is, the list content is the type of list, the direct use of list<list<integer>> list = new list<list<integer>> () is wrong, because list is the interface, Cannot instantiate (cannot instantiate the type list<list<integer>>).
But if you use
1 list<list<integer>> List = new linkedlist<linkedlist<integer>> ();
An error will be added (cannot convert from linkedlist<linkedlist<integer>> to list<list<integer>>),
The correct approach is to modify it into:
1 New Linkedlist<linkedlist<integer>>(); 3 or 5 New Linkedlist<list<integer>> ();
This is possible, that is, the generic type parameters must be the same.
The following treatment
1 New Arraylist<arraylist<string>>(); 2 or 3 New Linkedlist<linkedlist<string>> ();
It is also possible to do so without referencing the implementation class with the interface class .
Reference
1.Working with a List of Lists in Java
2.How do I initialize a two-dimensional List statically?
3.Initialize list<list<integer>> in Java
Java collection nested List of list