To append a list to another list in Dart, you can use the addAll
method of the List
class.
In this example,
list1
and list2
with initial values.addAll
method to append all elements of list2
to list1
.list1
to standard output.void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [4, 5, 6];
list1.addAll(list2);
print('Updated list: \$list1');
}
Updated list: [1, 2, 3, 4, 5, 6]
In this example,
list1
and list2
with initial values....
) to append all elements of list2
to list1
.list1
to standard output.void main() {
List<int> list1 = [1, 2, 3];
List<int> list2 = [4, 5, 6];
list1.addAll([...list2]);
print('Updated list: \$list1');
}
Updated list: [1, 2, 3, 4, 5, 6]
In this tutorial, we learned How to Append a List to another List in Dart language with well detailed examples.