Scala Iterator toArray() method with example
Last Updated :
13 Aug, 2019
The toArray() method belongs to the concrete value member of the class Abstract iterator. It is utilized to convert the stated collection to an array.
Method Definition: def toArray: Array[A]
Return Type: It returns an array from the elements of the iterator.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2 , 3 , 5 , 7 , 8 , 9 )
val result = iter.toArray
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 0 , 1 , 10 )
val result = iter.toArray
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...