Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

length
listqueue
dart
communitycreator

What is the ListQueue.length property in Dart?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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}");
}
Using lengh property to get the number of elements present in the queue

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.

RELATED TAGS

length
listqueue
dart
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring