ListQueue
is a List based onQueue
. Read more aboutListQueue
here.
The length
property gets the number of elements in the ListQueue
.
queue.length
This property doesn’t take any argument.
This property returns an int
value denoting the number of elements present in the queue.
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}");}
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.