Open In App

Scala Queue size() method with example

Last Updated : 29 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The size() method is utilized to return the number of elements present in the queue.

Method Definition: def size: Int

Return Type: It returns the number of elements present in the queue.

Example #1:




// Scala program of size() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a queue 
        val q1 = Queue(5, 2, 3, 7, 1
          
        // Print the queue
        println(q1)
          
        // Applying size method 
        val result = q1.size
          
        // Display output
        print("Number of elements in the queue: "  + result)
          
    


Output:

Queue(5, 2, 3, 7, 1)
Number of elements in the queue: 5

Example #2:




// Scala program of size() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a queue 
        val q1 = Queue("a", "e", "i", "o", "u"
          
        // Print the queue
        println(q1)
          
        // Applying size method 
        val result = q1.size
          
        // Display output
        print("Number of elements in the queue: "  + result)
          
    


Output:

Queue(a, e, i, o, u)
Number of elements in the queue: 5


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads