Scala Stack mkString() method with a separator with example
In Scala Stack class
, the mkString() method is utilized to display all the elements of the stack in a string along with a separator.
Method Definition: def mkString(sep: String): String
Return Type: It returns all the elements of the stack in a string along with a separator.
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: 1, 2, 3, 4
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: Geeks, for, Geeks
Last Updated :
03 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...