Scala Iterator toSeq() method with example
The toSeq() method belongs to the concrete value member of the class Abstract Iterator. It is equivalent to the Seq method but this method is more faster.
Method Definition: val result = iter.toSeq
Return Type: It returns the stated collection as a sequence.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2 , 5 , 7 , 8 , 9 )
val result = iter.toSeq
println(result)
}
}
|
So, here a sequence is obtained.
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val result = iter.toSeq
println(result)
}
}
|
So, here an empty iterator is obtained as the stated iterator is empty.
Last Updated :
13 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...