How to Combine Lists in Dart?

In Dart programming, the List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of List class, its creation, and manipulation. There are 5 ways to combine two or more list:

  1. Using addAll() method to add all the elements of another list to the existing list.
  2. Creating a new list by adding two or more lists using addAll() method of the list.
  3. Creating a new list by adding two or more list using expand() method of the list**.**
  4. Using + operator to combine list.
  5. Using spread operator to combine list.

Using addAll() method to add all the elements of other lists to the existing list

We can add all the elements of the other list to the existing list by the use of addAll() method. To learn about this method you can follow this article.

Example:

Dart

// Main function 
main() { 

  // Creating lists 
  List gfg1 = ['Welcome','to']; 
  List gfg2 = ['GeeksForGeeks']; 

  // Combining lists 
  gfg1.addAll(gfg2); 

  // Printing combined list 
  print(gfg1); 
}

#dart #dart-list

How to Combine Lists in Dart?
1.65 GEEK