📜  dart list add - Dart (1)

📅  最后修改于: 2023-12-03 15:30:21.927000             🧑  作者: Mango

Dart List Add

The dart list add command is used to add an element to a list in Dart programming language. This command is part of the dart:collection library which provides a set of collections that implement common data structures.

Syntax
void add(E value)

The add() method accepts a single parameter which is the value to be added to the list.

Example
import 'dart:collection';

void main() {
   // create a list
   var list = List<int>();
   
   // add some elements to the list
   list.add(10);
   list.add(20);
   list.add(30);

   // print list
   print(list);  
}
Output
[10, 20, 30]

In the above example, we have created an empty list using List<int>() constructor. We have used the add() method to add three elements to the list. Finally, we have printed the contents of the list using print() function.

That's it! Now you know how to add elements to a list using dart list add command in Dart programming language.