What is the ListQueue.length property in Dart?
ListQueueis a List based onQueue. Read more aboutListQueuehere.
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 objectListQueue queue = new ListQueue();// add two elementsqueue.add(10);queue.add(20);print("queue is : $queue");// get the length of the queueprint("Number of elements in the queue is : ${queue.length}");}
Explanation
In the above code:
-
In line 1: We import the
collectionlibrary. -
Line 4: We create a
ListQueuenamedqueue. -
Lines 6 and 7: We used the
addmethod to add two elements 10 and 20. -
Line 11: We use the
lengthproperty to get the number of elements present in thequeue. The queue has two elements in our case, so2is returned.