What is the queue.isNotEmpty method in Dart?

The queue.isNotEmpty function in Dart is used to check if a queue is empty. queue.isNotEmpty returns true if the queue is not empty. Otherwise, it returns false.

The image below shows the visual representation of the queue.isNotEmpty function.

Figure 1

The dart:collection module is required in order to use the queue.isNotEmpty function.

Syntax

bool queue.isNotEmpty

queue is the name of the queue.

Parameters

The queue.isNotEmpty function does not require any parameters.

Return value

If the queue is not empty, the queue.isNotEmpty function returns true. Otherwise, it returns false.

Code

The following code shows how to use the queue.isNotEmpty 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->0
print("queue_1 is not empty: ${queue_1.isNotEmpty}");
//Queue empty
Queue<int> queue_2 = new Queue<int>();
print("queue_2 is not empty: ${queue_2.isNotEmpty}");
}

Free Resources