Dart – Add Element to List
To add an element to a List in Dart, call add() method on this list and pass the element as argument. add() method returns nothing, void
, and modifies the original list.
Syntax
The syntax to add an element e
to a List list
is
list.add(e)
ADVERTISEMENT
Example
In this example, we take a list of integers with five elements, and add an element to it using List.add() method.
main.dart
void main() { var list = [2, 4, 8, 16, 32]; list.add(64); print('List : $list'); }
Output
List : [2, 4, 8, 16, 32, 64]
Conclusion
In this Dart Tutorial, we learned how to add an element to a list, with examples.