.add()
Anonymous contributor
Published Jul 9, 2024
Contribute to Docs
The .add()
method in Dart is used to append a single element to the end of a list. It modifies the original list and extends its length by one to accommodate the new element.
Syntax
listName.add(element);
element
: The element to be appended to the list.
Example
In the following example, the .add()
method appends the string ‘orange’ to the end of the fruits
list.
void main() {List<String> fruits = ['apple', 'banana'];fruits.add('orange');print(fruits);}
The output of the above code will be:
[apple, banana, orange]
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.