Skip to content
Related Articles

Related Articles

Improve Article
Scala Queue isEmpty() method with example
  • Last Updated : 29 Oct, 2019

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 q1 = Queue(1, 3, 2, 7, 6, 5
          
        // Print the queue
        println(q1)
          
        // Applying isEmpty method 
        val result = q1.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 q1 = Queue() 
          
        // Print the queue
        println(q1)
          
        // Applying isEmpty method 
        val result = q1.isEmpty
          
        // Display output
        print("The queue is empty: " + result)
          
    
Output:
Queue()
The queue is empty: true



My Personal Notes arrow_drop_up
Recommended Articles
Page :