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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources