What is the queue.length method in Dart?

The queue.length function in Dart returns the number of elements in the queue. In short, this function is used to get the current size of the queue.

The image below shows the visual representation of the queue.length function.

Visual representation of the queue.length function

Syntax


int queue_name.length
// where the queue_name is the name of the queue

Parameters

This function does not require a parameter.

Return value

The queue.length function returns the number of elements in the queue and is used to get the current size of the queue.

Code

The code below shows how to use the queue.length function in Dart.

import 'dart:convert';
import 'dart:collection';
void main() {
Queue<int> queue_1 = new Queue<int>();
queue_1.add(1);
queue_1.add(3);
queue_1.add(5);
queue_1.add(2);
queue_1.add(0);
//Queue filled= 1->3->5->2->0
print("queue_1 length: ${queue_1.length}");
//Queue empty
Queue<int> queue_2 = new Queue<int>();
print("queue_2 length: ${queue_2.length}");
}

Free Resources