Scala Iterator addString() method with example

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
      
    }
}

chevron_right


Output:

7681

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
          
    }
}

chevron_right


Output:

7.76.18.61.1


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.