Scala Iterator addString() method with a separator with example
This method is same as addString() method but here we can even include a separator between all the elements of an Iterator.
Method Definition : def addString(b: StringBuilder, sep: String): StringBuilder
Where, sep is the separator.
Return Type :It returns the elements of an iterator in the String Builder along with the separator stated.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 11 , 12 , 13 , 14 )
val result = iter.addString( new StringBuilder(), "#" )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 5 , 6 , 9 )
val result = iter.addString( new StringBuilder(), "*" )
println(result)
}
}
|
Last Updated :
30 Jun, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...