The dart:collection
library provides the advance collection support for the Dart language apart from the basic collections already provided by the dart:core
library.
It contains the DoubleLinkedQueue<E>
class which implements the abstract Queue<E>
class, using a doubly-linked list.
removeFirst()
methodThe DoubleLinkedQueue<E>
class contains the removeFirst()
method, which removes and returns the first element of the queue.
A queue is a
data structure. In a queue, the element that is added first will be deleted first. FIFO First In First Out
E removeFirst()
First, we import the dart:collection
library into our program.
import 'dart:collection';void main() {var animalQueue = DoubleLinkedQueue<String>();animalQueue.add("Monkey");animalQueue.add("Lion");animalQueue.add("Tiger");print('Printing Queue Elements');print(animalQueue);var elem1 = animalQueue.removeFirst();print('Removing ${elem1} from Queue using removeFirst()');print('Printing Queue Elements');print(animalQueue);}
DoubleLinkedQueue
class of type String
."Monkey"
, "Lion"
, and "Tiger"
to the queue using the add()
method.{Monkey, Lion, Tiger}
, and all the elements are added to the end of the queue because the queue is a FIFO data structure.removeFirst()
method and store the return value in a variable."Monkey"
is removed from the queue. The queue elements are displayed using the print()
function of the core
library.