From cd53101ce42fa5cf854ef41b5bb2b1f293b366cc Mon Sep 17 00:00:00 2001 From: Utkarsh-Singhal-26 Date: Sat, 17 Jan 2026 12:11:17 +0530 Subject: [PATCH 1/2] [Term Entry] Dart Queue: .first --- .../dart/concepts/queue/terms/first/first.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 content/dart/concepts/queue/terms/first/first.md diff --git a/content/dart/concepts/queue/terms/first/first.md b/content/dart/concepts/queue/terms/first/first.md new file mode 100644 index 00000000000..f94e21473e2 --- /dev/null +++ b/content/dart/concepts/queue/terms/first/first.md @@ -0,0 +1,56 @@ +--- +Title: '.first' +Description: 'Returns the first element in a queue.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'Dart' + - 'Queues' + - 'Properties' +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the **`.first`** property returns the first element in a `Queue`. This property is part of the `Queue` class under the `dart:collection` library. + +## Syntax +```pseudo +queue.first; +``` + +**Return value:** + +Returns the first element in the queue. + +> **Note:** If the queue is empty, accessing this property throws a `StateError`. + +## Example + +The following example demonstrates the usage of the `.first` property: +```dart +import 'dart:collection'; + +void main() { + Queue numbers = Queue(); + numbers.add(10); + numbers.add(20); + numbers.add(30); + numbers.add(40); + + print("First element: ${numbers.first}"); + + // Modifying the first element + numbers.first = 5; + print("Updated first element: ${numbers.first}"); +} +``` + +The output for the above code is as follows: +```shell +First element: 10 +Updated first element: 5 +``` + +> **Note:** The `.first` property can also be used to modify the first element of the queue, as shown in the example above. \ No newline at end of file From aabca95449d73669faa3b413bf07f5f9474b6da7 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 19 Jan 2026 22:27:20 +0530 Subject: [PATCH 2/2] Clarify usage of .first property in Queue example Updated the example to clarify that the .first property can be used to access the first element of a Queue. Removed the code that modifies the first element to avoid confusion. --- content/dart/concepts/queue/terms/first/first.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/content/dart/concepts/queue/terms/first/first.md b/content/dart/concepts/queue/terms/first/first.md index f94e21473e2..5e8d5a5bf61 100644 --- a/content/dart/concepts/queue/terms/first/first.md +++ b/content/dart/concepts/queue/terms/first/first.md @@ -16,6 +16,7 @@ CatalogContent: In Dart, the **`.first`** property returns the first element in a `Queue`. This property is part of the `Queue` class under the `dart:collection` library. ## Syntax + ```pseudo queue.first; ``` @@ -26,9 +27,10 @@ Returns the first element in the queue. > **Note:** If the queue is empty, accessing this property throws a `StateError`. -## Example +## Example: Accessing the First Element of a `Queue` The following example demonstrates the usage of the `.first` property: + ```dart import 'dart:collection'; @@ -40,17 +42,11 @@ void main() { numbers.add(40); print("First element: ${numbers.first}"); - - // Modifying the first element - numbers.first = 5; - print("Updated first element: ${numbers.first}"); } ``` The output for the above code is as follows: + ```shell First element: 10 -Updated first element: 5 ``` - -> **Note:** The `.first` property can also be used to modify the first element of the queue, as shown in the example above. \ No newline at end of file