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:
// 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
Contact Us