Scala Iterator toString() method with example
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:
// 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
filter_none
Output:
non-empty iterator
Example #2:
// 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
filter_none
Output:
empty iterator
In above example, iterator is empty so produced result is also empty iterator.
Recommended Posts:
- Scala Iterator sum() method with example
- Scala Iterator map() method with example
- Scala Iterator min() method with example
- Scala Iterator max() method with example
- Scala Iterator next() method with example
- Scala Iterator seq() method with example
- Scala Map iterator method with example
- Scala Iterator zip() method with example
- Scala Iterator take() method with example
- Scala Iterator exists() method with example
- Scala Iterator dropWhile() method with example
- Scala Iterator find() method with example
- Scala Iterator filterNot() method with example
- Scala Iterator filter() method with example
- Scala Iterator forall() method with example
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.


