Open In App
Related Articles

Scala Queue isEmpty() method with example

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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


Last Updated : 29 Oct, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads