Dart .add()

Anonymous contributor's avatar
Anonymous contributor
Published Apr 13, 2024
Contribute to Docs

In Dart, the .add() method is used to insert a specified element to the end of a queue. This method is part of the Queue class under the dart:collection library.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

queue.add(element);
  • queue: The name of the queue to which a value is to be inserted.
  • element: The value to be inserted.

Example

The following example demonstrates the usage of the .add() method:

import 'dart:collection';
void main() {
Queue values = new Queue();
values.add(12);
values.add(24);
values.add(36);
values.add(48);
for(var num in values) {
print(num);
}
}

The output for the above code is as follows:

12
24
36
48

All contributors

Contribute to Docs

Learn Dart on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours