Related Articles

Related Articles

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of toString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(2, 1, 10)
          
        // Applying toString method 
        val result = iter.toString
          
        // Displays output
        println(result)
      
    }
}

chevron_right


Output:



non-empty iterator

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of toString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating an empty Iterator 
        val iter = Iterator()
          
        // Applying toString method 
        val result = iter.toString
          
        // Displays output
        println(result)
      
    }
}

chevron_right


Output:

empty iterator

In above example, iterator is empty so produced result is also empty iterator.




My Personal Notes arrow_drop_up
Recommended Articles
Page :