Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions content/dart/concepts/queue/terms/elementAt/elementAt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
Title: '.elementAt()'
Description: 'Returns the element at the specified index in a queue.'
Subjects:
- 'Computer Science'
- 'Code Foundations'
Tags:
- 'Dart'
- 'Queues'
- 'Methods'
CatalogContent:
- 'learn-dart'
- 'paths/computer-science'
---

In Dart, the **`.elementAt()`** method returns the element at the specified index in a queue. This method is part of the `Queue` class under the `dart:collection` library.

## Syntax
```pseudo
queue.elementAt(index);
```

- `queue`: The name of the queue from which an element is to be retrieved.
- `index`: The zero-based position of the element to be retrieved.

> **Note:** If the index is out of range, this method throws a `RangeError`.

## Example

The following example demonstrates the usage of the `.elementAt()` method:
```dart
import 'dart:collection';

void main() {
Queue<int> numbers = Queue<int>();

numbers.add(10);
numbers.add(20);
numbers.add(30);
numbers.add(40);

print("Element at index 0: ${numbers.elementAt(0)}");
print("Element at index 2: ${numbers.elementAt(2)}");
}
```

The output for the above code is as follows:
```shell
Element at index 0: 10
Element at index 2: 30
```