From 483146bb21a2597f1522f2359fa6891bec8a1a8b Mon Sep 17 00:00:00 2001 From: Vincent DiBernardo Date: Mon, 12 Jan 2026 14:04:04 -0800 Subject: [PATCH 1/2] Dart Queue: .last --- .../dart/concepts/queue/terms/last/last.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 content/dart/concepts/queue/terms/last/last.md diff --git a/content/dart/concepts/queue/terms/last/last.md b/content/dart/concepts/queue/terms/last/last.md new file mode 100644 index 00000000000..94f723dc85c --- /dev/null +++ b/content/dart/concepts/queue/terms/last/last.md @@ -0,0 +1,47 @@ +--- +Title: '.last' +Description: 'Returns the last element of a collection.' +Subjects: + - 'Computer Science' + - 'Developer Tools' + +Tags: + - 'Collections' + - 'Dart' + - 'Queues' + +CatalogContent: + - 'learn-dart' + - 'paths/computer-science' +--- + +In Dart, the **'.last'** property returns the final element in a collection, such as a 'Queue', 'List', or 'Set'. + +When used on a 'Queue', it allows for quick access to the element that was most recently added, or the element at the end of the iterable sequence without removing it. + +## Syntax + +```pseudo +collection.last +``` + +## Example + +The below example creates a list named 'List', appends two integer elements to it, and returns the last object in the list using the '.last' property: + +```dart +import 'dart:collection'; + +void main() { + var lst = new List(); + lst.add(7); + lst.add(8); + print("The last element of the list is: ${lst.last}) +} +``` + +It will produce the following output: + +```shell +The last element of the list is: 8 +``` \ No newline at end of file From 2b1b362b3d6290696badcff763ea14ce79ec3e80 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 19 Jan 2026 22:42:18 +0530 Subject: [PATCH 2/2] Clarify '.last' property usage in Dart queues Updated the description and example for the '.last' property in Dart to clarify its function with queues. --- .../dart/concepts/queue/terms/last/last.md | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/content/dart/concepts/queue/terms/last/last.md b/content/dart/concepts/queue/terms/last/last.md index 94f723dc85c..3ada6988646 100644 --- a/content/dart/concepts/queue/terms/last/last.md +++ b/content/dart/concepts/queue/terms/last/last.md @@ -1,23 +1,21 @@ --- Title: '.last' -Description: 'Returns the last element of a collection.' +Description: 'Returns the last element in a queue without removing it.' Subjects: - 'Computer Science' - 'Developer Tools' - Tags: - 'Collections' - 'Dart' - 'Queues' - CatalogContent: - 'learn-dart' - 'paths/computer-science' --- -In Dart, the **'.last'** property returns the final element in a collection, such as a 'Queue', 'List', or 'Set'. +In Dart, the **`.last`** property returns the last element in a `Queue` without modifying the queue. It provides read-only access to the element at the end of the queue. -When used on a 'Queue', it allows for quick access to the element that was most recently added, or the element at the end of the iterable sequence without removing it. +This property is part of the `Queue` class from the `dart:collection` library and is commonly used when you need to inspect the most recently added element or the final element in the queue. ## Syntax @@ -25,23 +23,39 @@ When used on a 'Queue', it allows for quick access to the element that was most collection.last ``` -## Example +**Parameters:** + +This property does not take any parameters. + +**Return value:** + +Returns the last element in the queue. + +> **Note:** If the queue is empty, accessing `.last` throws a `StateError`. -The below example creates a list named 'List', appends two integer elements to it, and returns the last object in the list using the '.last' property: +## Example: Accessing the Last Element of a Queue + +This example demonstrates how to retrieve the last element from a queue without removing it: ```dart import 'dart:collection'; void main() { - var lst = new List(); - lst.add(7); - lst.add(8); - print("The last element of the list is: ${lst.last}) + Queue numbers = Queue(); + + numbers.add(10); + numbers.add(20); + numbers.add(30); + numbers.add(40); + + print('Last element: ${numbers.last}'); } ``` It will produce the following output: ```shell -The last element of the list is: 8 -``` \ No newline at end of file +Last element: 40 +``` + +The queue remains unchanged after accessing `.last`, making it useful for inspection or conditional logic without altering the data structure.