Scala Iterator toString() method with example
Last Updated :
13 Aug, 2019
The toString() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to convert the stated iterator to a string.
Method Definition: def toString(): String
Return Type: It returns a string from the stated iterator.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2 , 1 , 10 )
val result = iter.toString
println(result)
}
}
|
Output:
non-empty iterator
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val result = iter.toString
println(result)
}
}
|
In above example, iterator is empty so produced result is also empty iterator.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...