The queue.first
function in Dart is used to get the reference of the first element in the queue.
Figure 1 shows the visual representation of the queue.first
function.
The following module is required in order to use the function dart:collection
:
element queue_name.first
// where the queue_name is the name of the queue
This function does not require a parameter.
The function queue.first
returns the reference to the queue’s first element.
- It does not remove that element from the queue.
- If the queue is
empty
then it throws anerror
.
The following code shows how to use queue.first
function in Dart.
import 'dart:convert';import 'dart:collection';void main() {Queue<int> queue_1 = new Queue<int>();queue_1.add(1);queue_1.add(3);queue_1.add(5);queue_1.add(2);queue_1.add(0);//Queue filled= 1->3->5->2->0print("The elements of queue_1: ${queue_1}");print("The first element of queue_1: ${queue_1.first}");}