Skip to content
Related Articles

Related Articles

Scala Iterator toArray() method with example
  • Last Updated : 13 Aug, 2019
GeeksforGeeks - Summer Carnival Banner

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:




// Scala program of toArray()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(2, 3, 5, 7, 8, 9)
          
        // Applying toArray method 
        val result = iter.toArray
          
        // Displays output
        println(result)
      
    }
}
Output:



[I@506e1b77

Example #2:




// Scala program of toArray()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(0, 1, 10)
          
        // Applying toArray method 
        val result = iter.toArray
          
        // Displays output
        println(result)
      
    }
}
Output:
[I@3535dee8

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :