In Dart, you can create a list of lists using the `List>` class and add lists as elements of the outer list.
In this example,
list1
and list2
.listOfLists
of type List>
and initialize it with the inner lists.void main() {
List<int> list1 = [1, 2, 3];
List<String> list2 = ['a', 'b', 'c'];
List<List<dynamic>> listOfLists = [list1, list2];
print(listOfLists);
}
[[1, 2, 3], [a, b, c]]
In this example,
listOfListsEmpty
of type List>
.list3
and list4
.add
method to add the inner lists list3
and list4
to the outer list listOfListsEmpty
.void main() {
List<List<dynamic>> listOfListsEmpty = [];
List<dynamic> list3 = [];
List<dynamic> list4 = [];
listOfListsEmpty.add(list3);
listOfListsEmpty.add(list4);
print(listOfListsEmpty);
}
[[], []]
In this tutorial, we learned How to create a List of Lists in Dart language with well detailed examples.