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..5e8d5a5bf61 --- /dev/null +++ b/content/dart/concepts/queue/terms/first/first.md @@ -0,0 +1,52 @@ +--- +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: Accessing the First Element of a `Queue` + +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}"); +} +``` + +The output for the above code is as follows: + +```shell +First element: 10 +```