What is the ListQueue.length property in Dart?

ListQueue is a List based on Queue. Read more about ListQueue here.

The length property gets the number of elements in the ListQueue.

Syntax

queue.length

Parameter

This property doesn’t take any argument.

Return value

This property returns an int value denoting the number of elements present in the queue.

Code

The code below demonstrates how to get the number of elements present in the queue:

import 'dart:collection';
void main() {
//create a new ListQueue object
ListQueue queue = new ListQueue();
// add two elements
queue.add(10);
queue.add(20);
print("queue is : $queue");
// get the length of the queue
print("Number of elements in the queue is : ${queue.length}");
}

Explanation

In the above code:

  • In line 1: We import the collection library.

  • Line 4: We create a ListQueue named queue.

  • Lines 6 and 7: We used the add method to add two elements 10 and 20.

  • Line 11: We use the length property to get the number of elements present in the queue. The queue has two elements in our case, so 2 is returned.

Free Resources