The addLast method is used to add an element at the end of the ListQueue.
We can use the add or addFirst methods to add an element at the start of the ListQueue.
Note:
ListQueueis a List based onQueue. Read more aboutListQueuehere.
// add element at end
void addLast(E value)
// add element at start
void add(E value)
void addFirst(E value)
The element to be added to the queue is passed as a parameter.
This method doesn’t return any value.
The code below demonstrates how to add an element to the start and end of the ListQueue:
import 'dart:collection';void main() {// create a queueListQueue queue = new ListQueue();// add element 10 to end of the queuequeue.addLast(10);print("queue is : $queue");// add element 20 to start of the queuequeue.addFirst(20);print("queue is : $queue");// add element 30 to start of the queuequeue.add(30);print("queue is : $queue");}
In the code above:
Line 1: We import the collection library.
Line 4: We create a ListQueue with the name queue.
Line 7: We use the addlast method to add element 10 as the last element of the queue. Now the queue is {10}.
Line 11: We use the addFirstt method to add element 20 as the first element of the queue. Now the queue is {20,10}.
Line 15: We use the add method to add element 30 as the last element of the queue. Now the queue is {20,10,30}.