Scala Queue size() method with example
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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 5 , 2 , 3 , 7 , 1 )
println(q 1 )
val result = q 1 .size
print( "Number of elements in the queue: " + result)
}
}
|
Output:
Queue(5, 2, 3, 7, 1)
Number of elements in the queue: 5
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( "a" , "e" , "i" , "o" , "u" )
println(q 1 )
val result = q 1 .size
print( "Number of elements in the queue: " + result)
}
}
|
Output:
Queue(a, e, i, o, u)
Number of elements in the queue: 5
Last Updated :
29 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...