The isEmpty() is utilized to check if the queue is empty or not.
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the queue is empty or else it returns false.
Example #1:
// Scala program of isEmpty() // method // Import Queue import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating a queue
val q 1 = Queue( 1 , 3 , 2 , 7 , 6 , 5 )
// Print the queue
println(q 1 )
// Applying isEmpty method
val result = q 1 .isEmpty
// Display output
print( "The queue is empty: " + result)
}
} |
Output:
Queue(1, 3, 2, 7, 6, 5) The queue is empty: false
Example #2:
// Scala program of isEmpty() // method // Import Queue import scala.collection.mutable. _
// Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Creating a queue
val q 1 = Queue()
// Print the queue
println(q 1 )
// Applying isEmpty method
val result = q 1 .isEmpty
// Display output
print( "The queue is empty: " + result)
}
} |
Output:
Queue() The queue is empty: true