Scala Stack mkString() method with example
Last Updated :
03 Nov, 2019
In Scala Stack class
, the mkString() method is utilized to display all elements of the stack in a string.
Method Definition: def mkString: String
Return Type: It returns a string containing all the element of the stack.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 1 , 2 , 3 , 4 )
println(s 1 )
val result = s 1 .mkString
print( "Stack: " + result)
}
}
|
Output:
Stack(1, 2, 3, 4)
Stack: 1234
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( "Geeks" , "for" , "Geeks" )
println(s 1 )
val result = s 1 .mkString
print( "Stack: " + result)
}
}
|
Output:
Stack(Geeks, for, Geeks)
Stack: GeeksforGeeks
Share your thoughts in the comments
Please Login to comment...