From c7e760c9ece3a2db68f7dc14ce8f906fafe240c6 Mon Sep 17 00:00:00 2001 From: Owen Date: Tue, 9 Dec 2025 14:57:10 +0000 Subject: [PATCH 1/2] Add Dart Map .addEntries() term entry --- .../map/terms/add-entries/add-entries.md | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 content/dart/concepts/map/terms/add-entries/add-entries.md diff --git a/content/dart/concepts/map/terms/add-entries/add-entries.md b/content/dart/concepts/map/terms/add-entries/add-entries.md new file mode 100644 index 00000000000..dac4737181d --- /dev/null +++ b/content/dart/concepts/map/terms/add-entries/add-entries.md @@ -0,0 +1,54 @@ +--- +Title: '.addEntries()' +Description: 'Adds multiple key-value pairs to an existing Map using an iterable of MapEntry objects.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Dart' + - 'Map' + - 'Methods' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the **`.addEntries()`** method allows you to add multiple key-value pairs to an existing `Map` by providing it with an iterable of `MapEntry` objects. This is useful when inserting several entries at once, especially when transforming lists into maps or combining data from multiple sources. + +## Syntax + +```pseudo +mapVariable.addEntries(iterableOfMapEntries) +``` + +- `mapVariable`: The map you want to add entries into. +- `iterableOfMapEntries`: An iterable containing `MapEntry` objects (`MapEntry(key, value)`). + +## Example + +The following example demonstrates how `.addEntries()` can be used to add multiple entries to a `Map`: + +```dart +void main() { + Map inventory = { + 'Apples': 5, + 'Bananas': 3 + }; + + // Creating an iterable of MapEntry objects + var newItems = [ + MapEntry('Oranges', 4), + MapEntry('Grapes', 10) + ]; + + inventory.addEntries(newItems); + + print(inventory); +} +``` + +**Output:** + +```shell +{Apples: 5, Bananas: 3, Oranges: 4, Grapes: 10} +``` From 4dddbe4e7c4cc5a39eba6452e967dbd828ae189d Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Wed, 10 Dec 2025 13:56:41 +0530 Subject: [PATCH 2/2] Refine .addEntries() method documentation Clarified the explanation of the .addEntries() method and updated parameter descriptions. --- .../concepts/map/terms/add-entries/add-entries.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/content/dart/concepts/map/terms/add-entries/add-entries.md b/content/dart/concepts/map/terms/add-entries/add-entries.md index dac4737181d..7367e439474 100644 --- a/content/dart/concepts/map/terms/add-entries/add-entries.md +++ b/content/dart/concepts/map/terms/add-entries/add-entries.md @@ -13,7 +13,7 @@ CatalogContent: - 'paths/computer-science' --- -In Dart, the **`.addEntries()`** method allows you to add multiple key-value pairs to an existing `Map` by providing it with an iterable of `MapEntry` objects. This is useful when inserting several entries at once, especially when transforming lists into maps or combining data from multiple sources. +In Dart, the **`.addEntries()`** method adds multiple key-value pairs to an existing `Map` using an iterable of `MapEntry` objects. It’s useful for inserting several entries at once, such as when transforming lists into maps or merging data. ## Syntax @@ -21,8 +21,13 @@ In Dart, the **`.addEntries()`** method allows you to add multiple key-value pai mapVariable.addEntries(iterableOfMapEntries) ``` -- `mapVariable`: The map you want to add entries into. -- `iterableOfMapEntries`: An iterable containing `MapEntry` objects (`MapEntry(key, value)`). +**Parameters:** + +- `iterableOfMapEntries`: An iterable of `MapEntry` objects, where `K` and `V` match the map’s key and value types. + +**Return value:** + +- `void`: The method does not return anything; it modifies the existing map in place. ## Example @@ -47,7 +52,7 @@ void main() { } ``` -**Output:** +The output of this code is as follows: ```shell {Apples: 5, Bananas: 3, Oranges: 4, Grapes: 10}