Open In App

Scala Iterator addString() method with example

Improve
Improve
Like Article
Like
Save
Share
Report

The addString() method belongs to the concrete value members of the class AbstractIterator. It is defined in the class IterableOnceOps. It is utilized to append the elements of the Scala Iterator to a String Builder.

Method Definition : def addString(b: StringBuilder): StringBuilder

Return Type : It returns the String Builder to which the elements were appended.

Example #1:




// Scala program of addString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating an Iterator 
        val iter = Iterator(7, 6, 8, 1)
          
        // Applying addString method 
        val result = iter.addString(new StringBuilder())
          
        // Displays output
        println(result)
      
    }
}


Output:

7681

Example #2:




// Scala program of addString()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating an Iterator 
        val iter = Iterator(7.7, 6.1, 8.6, 1.1)
          
        // Applying addString method 
        val result = iter.addString(new StringBuilder())
          
        // Displays output
        println(result)
          
    }
}


Output:

7.76.18.61.1


Last Updated : 30 Jun, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads