Scala Queue toList() method with example
The toList() method is utilized to return a list consisting of all the elements of the queue.
Method Definition: def toList: List[A]
Return Type: It returns a list consisting of all the elements of the queue.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 1 , 2 , 3 , 4 , 5 )
println(q 1 )
val result = q 1 .toList
print( "Elements in the list: " )
for (elem < - result)
print(elem + " " )
}
}
|
Output:
Queue(1, 2, 3, 4, 5)
Elements in the list: 1 2 3 4 5
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 5 , 2 , 13 , 7 , 1 )
println(q 1 )
val result = q 1 .toList
print( "Elements in the list: " )
for (elem < - result)
print(elem + " " )
}
}
|
Output:
Queue(5, 2, 13, 7, 1)
Elements in the list: 5 2 13 7 1
Last Updated :
29 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...