The queue.isEmpty
function in Scala is used to check if a queue is empty or not.
The illustration below shows the visual representation of the queue.isEmpty
function.
The following module is required in order to use the function:
scala.collection.mutable.Queue
queue_name.isEmpty;
// where the queue_name is the name of the queue
The queue.isEmpty
function does not require any parameters.
If the queue is empty, the queue.isEmpty
function returns true
. Otherwise, it returns false
.
The following code shows how to use queue.isEmpty
function in Scala.
import scala.collection.mutable.Queueobject Main extends App {var queue = Queue[Int]()queue.enqueue(1);queue.enqueue(3);queue.enqueue(5);queue.enqueue(2);queue.enqueue(0);//filled queueprintln("The Queue is empty: " + queue.isEmpty);var queue_2 = Queue[Int]()//empty queueprintln("The Queue is empty: " + queue_2.isEmpty);}