From 2d88e4aea6f2892b13b9dff6e3a1eec0b2a6ff6d Mon Sep 17 00:00:00 2001 From: Alan Baum Date: Sun, 11 Jan 2026 16:45:39 +0000 Subject: [PATCH 1/2] Add Dart Queue isNotEmpty docs entry --- .../queue/terms/isNotEmpty/isNotEmpty.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md diff --git a/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md b/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md new file mode 100644 index 00000000000..faeb225abc2 --- /dev/null +++ b/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md @@ -0,0 +1,22 @@ +--- +Title: '.isNotEmpty' +Description: 'Returns true if the Queue is not empty.' +Subjects: + - 'Computer Science' +Tags: + - 'Dart' + - 'Queue' + - 'Properties' +CatalogContent: + - 'learn-dart' +--- + +## Introduction + +The `.isNotEmpty` property in Dart is used to check whether a `Queue` contains at least one element. It returns `true` if the queue has one or more items, and `false` if the queue is empty. + +## Syntax + +```dart +queue.isNotEmpty + From 0431f13f4c720751640fd25541935ebdae0b3b54 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 12 Jan 2026 17:37:54 +0530 Subject: [PATCH 2/2] Enhance documentation for .isNotEmpty property Updated the description for the .isNotEmpty property and added detailed examples demonstrating its usage in Dart. --- .../queue/terms/isNotEmpty/isNotEmpty.md | 72 +++++++++++++++++-- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md b/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md index faeb225abc2..c9ace3c0ee9 100644 --- a/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md +++ b/docs/content/dart/concepts/queue/terms/isNotEmpty/isNotEmpty.md @@ -1,7 +1,8 @@ --- Title: '.isNotEmpty' -Description: 'Returns true if the Queue is not empty.' +Description: 'Returns true if the queue is not empty.' Subjects: + - 'Code Foundations' - 'Computer Science' Tags: - 'Dart' @@ -9,14 +10,75 @@ Tags: - 'Properties' CatalogContent: - 'learn-dart' + - 'paths/computer-science' --- -## Introduction - -The `.isNotEmpty` property in Dart is used to check whether a `Queue` contains at least one element. It returns `true` if the queue has one or more items, and `false` if the queue is empty. +In Dart, the **`.isNotEmpty`** property checks whether a `Queue` contains one or more elements. It returns `true` if the queue has at least one element and `false` if the queue is empty. This property is commonly used in conditional logic before accessing or removing elements from a queue. ## Syntax -```dart +```pseudo queue.isNotEmpty +``` + +**Parameters:** + +- This property takes no parameters. + +**Return value:** + +Returns a boolean value: + +- `true` if the queue contains at least one element +- `false` if the queue is empty + +## Example 1: Checking Queue State + +This example demonstrates how `.isNotEmpty` can be used to verify whether a queue has elements before performing operations on it: + +```dart +import 'dart:collection'; + +void main() { + Queue numbers = Queue(); + + numbers.add(10); + numbers.add(20); + + print(numbers.isNotEmpty); +} +``` + +The output of this code is: + +```shell +true +``` + +## Example 2: Using `.isNotEmpty` in a Loop + +This example shows how `.isNotEmpty` can be used to safely process and remove elements from a queue until it becomes empty: + +```dart +import 'dart:collection'; + +void main() { + Queue tasks = Queue(); + + tasks.addAll(['Task A', 'Task B', 'Task C']); + + while (tasks.isNotEmpty) { + print('Processing ${tasks.removeFirst()}'); + } +} +``` + +The output of this code is: + +```shell +Processing Task A +Processing Task B +Processing Task C +``` +This pattern ensures that elements are only removed while the queue contains items, preventing runtime errors.