Introduction
A Queue is a collection that can easily be manipulated from both ends. ForEach or an Iterator can be used to iterate over the elements of a queue.
In this article, we will be learning about Dart Queues, their initialization, methods & properties with an example.
Before learning how we do so, learning the basic Introduction of Dart is recommended.
So, let us start reading about Queues in Dart.
Queues In Dart
Dart also allows users to manipulate data in the form of a queue. A queue is a First In, First Out (FIFO) Data Structure in which the first thing added is discarded first. It takes the data from the first end and removes it from the second end. So, When you want to create a first-in, first-out data collection, queues come in handy. Now let us see the ways of creating a queue in Dart.
Creating Queue using Constructor
Let us see the syntax for creating a Queue in Dart and then inserting the elements in it.
Syntax:
Queue var_name = new Queue();
Input:
import 'dart:collection';
void main()
{
// Creating Queue with var_name codeStudio
Queue<String> codeStudio = new Queue<String>();
// Adding elements
codeStudio.add("Code");
codeStudio.add("Studio");
codeStudio.add("Blog");
// Printing all the inserted elements
print(codeStudio);
}
Output:
{Code, Studio, Blog}
Creating Queue Using Existing List
Now, let us see the syntax for creating a Queue in Dart through Existing List and then inserting the elements in it.
Syntax:
Queue<E> var_name = new Queue<E>.from(list_name); // With type notation(E)
var var_name = new Queue.from(list_name); // Without type notation
Input:
import 'dart:collection';
void main()
{
// Creating List
List<String> my_list = ["Code","Studio","Blog"];
// Creating a Queue (my_queue) through a List (my_list)
Queue<String> my_queue = new Queue<String>.from(my_list);
// Printing elements of the queue my_queue
print(my_queue);
}
Output:
{Code, Studio, Blog}




