From 5397916a382b782be9c12139dce84788f10504a3 Mon Sep 17 00:00:00 2001 From: kumud Date: Fri, 16 Jan 2026 10:37:45 +0000 Subject: [PATCH 1/2] Add .isNotEmpty term entry for Dart Map --- .../map/terms/is-not-empty/is-not-empty.md | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md diff --git a/docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md b/docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md new file mode 100644 index 00000000000..37afe4dbaa5 --- /dev/null +++ b/docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md @@ -0,0 +1,54 @@ +--- +title: .isNotEmpty +description: "Checks whether a Dart Map contains at least one key-value pair." +keywords: [dart, map, collection, isNotEmpty, term] +--- + +**Checks whether a Dart `Map` contains at least one key-value pair.** + +## Introduction + +In Dart, the `.isNotEmpty` property is used to determine whether a `Map` contains one or more entries. It returns a boolean value: `true` if the map has at least one key-value pair, and `false` if the map is empty. + +This property is commonly used to guard against performing operations—such as iteration or value access—on empty maps, improving code safety and readability. + +--- + +## Syntax + +```dart +map.isNotEmpty +``` + +## Example + +```dart +void main() { + Map countryCodes = { + 'US': 'United States', + 'IN': 'India', + }; + + if (countryCodes.isNotEmpty) { + countryCodes.forEach((code, country) { + print('$code -> $country'); + }); + } else { + print('The map is empty.'); + } + + Map emptyMap = {}; + + print(emptyMap.isNotEmpty); // false +} + +``` +## Tip + +Use `.isNotEmpty` instead of `map.length > 0` for clearer intent and better readability. + +## See also + +- .isEmpty — Checks whether a map contains no entries + +- .length — Returns the number of entries in a map \ No newline at end of file From 3c80b595ed86a534cb0ae6fbf3c895fb5678eed9 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 19 Jan 2026 22:20:36 +0530 Subject: [PATCH 2/2] Revise .isNotEmpty documentation for clarity Updated the documentation for the .isNotEmpty property to clarify its usage and return value. Enhanced structure with subjects, tags, and catalog content. --- .../map/terms/is-not-empty/is-not-empty.md | 68 +++++++++++++++++++ .../map/terms/is-not-empty/is-not-empty.md | 54 --------------- 2 files changed, 68 insertions(+), 54 deletions(-) create mode 100644 content/dart/concepts/map/terms/is-not-empty/is-not-empty.md delete mode 100644 docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md diff --git a/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md b/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md new file mode 100644 index 00000000000..0e20a122ec4 --- /dev/null +++ b/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md @@ -0,0 +1,68 @@ +--- +Title: '.isNotEmpty' +Description: 'Returns true if a Map contains one or more key-value pairs.' +Subjects: + - 'Computer Science' + - 'Code Foundations' +Tags: + - 'Dart' + - 'Map' + - 'Properties' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the **`.isNotEmpty`** property is used to check whether a `Map` contains at least one key-value pair. It returns `true` if the map has one or more entries, and `false` if the map is empty. + +This property is commonly used in conditional checks to ensure a map has data before accessing or processing its contents. + +## Syntax + +```pseudo +map.isNotEmpty +``` + +**Parameters:** + +This property does not take any parameters. + +**Return value:** + +Returns a boolean value: + +- `true`: The map contains one or more key-value pairs. +- `false`: The map contains no key-value pairs. + +## Example: Checking for Entries Before Iterating Over a Map + +This example demonstrates how `.isNotEmpty` can be used to iterate over a map only when it contains data. It also shows how the property behaves when applied to an empty map: + +```dart +void main() { + Map countryCodes = { + 'US': 'United States', + 'IN': 'India', + }; + + if (countryCodes.isNotEmpty) { + countryCodes.forEach((code, country) { + print('$code -> $country'); + }); + } else { + print('The map is empty.'); + } + + Map emptyMap = {}; + + print(emptyMap.isNotEmpty); // false +} +``` + +The output of this code is: + +```shell +US -> United States +IN -> India +false +``` diff --git a/docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md b/docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md deleted file mode 100644 index 37afe4dbaa5..00000000000 --- a/docs/content/dart/concepts/map/terms/is-not-empty/is-not-empty.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: .isNotEmpty -description: "Checks whether a Dart Map contains at least one key-value pair." -keywords: [dart, map, collection, isNotEmpty, term] ---- - -**Checks whether a Dart `Map` contains at least one key-value pair.** - -## Introduction - -In Dart, the `.isNotEmpty` property is used to determine whether a `Map` contains one or more entries. It returns a boolean value: `true` if the map has at least one key-value pair, and `false` if the map is empty. - -This property is commonly used to guard against performing operations—such as iteration or value access—on empty maps, improving code safety and readability. - ---- - -## Syntax - -```dart -map.isNotEmpty -``` - -## Example - -```dart -void main() { - Map countryCodes = { - 'US': 'United States', - 'IN': 'India', - }; - - if (countryCodes.isNotEmpty) { - countryCodes.forEach((code, country) { - print('$code -> $country'); - }); - } else { - print('The map is empty.'); - } - - Map emptyMap = {}; - - print(emptyMap.isNotEmpty); // false -} - -``` -## Tip - -Use `.isNotEmpty` instead of `map.length > 0` for clearer intent and better readability. - -## See also - -- .isEmpty — Checks whether a map contains no entries - -- .length — Returns the number of entries in a map \ No newline at end of file