Scala Queue toString() method with example
Last Updated :
29 Oct, 2019
The toString() method is utilized to return a string representation of the queue object.
Method Definition: def toString(): String
Return Type: It returns a string representation of the queue object.
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 .toString
print( "String representation of the queue object: " + result)
}
}
|
Output:
Queue(1, 2, 3, 4, 5)
String representation of the queue object: Queue(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 , 3 )
println(q 1 )
val result = q 1 .toString
print( "String representation of the queue object: " + result)
}
}
|
Output:
Queue(5, 2, 13, 7, 1, 3)
String representation of the queue object: Queue(5, 2, 13, 7, 1, 3)
Share your thoughts in the comments
Please Login to comment...