Dart .addAll()
Anonymous contributor
Published Jan 5, 2026
Contribute to Docs
In Dart, the .addAll() method adds all key-value pairs from another Map into an existing Map. This is commonly used when merging maps or inserting multiple entries at once.
If a key from the source map already exists in the target map, its value will be replaced by the value from the source map.
Syntax
mapVariable.addAll(otherMap)
mapVariable is the Map object to which new key–value pairs will be added.
Parameters:
otherMap: A map whose key–value pairs are added tomapVariable. If a key already exists, its value is overwritten.
Return value:
This method returns void. The original map is modified in place.
Example
The following example demonstrates how .addAll() can be used to merge two maps:
void main() {Map<String, int> inventory = {'Apples': 5,'Bananas': 3};Map<String, int> newItems = {'Oranges': 4,'Grapes': 10};inventory.addAll(newItems);print(inventory);}
The output of this code is as follows:
{Apples: 5, Bananas: 3, Oranges: 4, Grapes: 10}
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.
Learn Dart on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours