Scala Iterator toIterable() method with example
The toIterable() belongs to the concrete value members of the Class AbstractIterator. It is defined in the classes TraversableOnce and GenTraversableOnce. It converts the stated traversable or iterator to an iterable collection. It won’t end for infinite-sized collections.
Method Definition : def toIterable: Iterable[A]
Return Type : It returns an Iterable containing all elements of the stated traversable or iterator.
Example :
// Scala program of toIterable() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Declaring an iterator val iter = Iterator(3, 2, 5, 9) // Applying toIterable method val result = iter.toIterable // Displays output println(result) } } |
Stream(3, ?)
Here, a Stream is returned from the stated iterator.
Example :
// Scala program of toIterable() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Declaring an empty-iterator val iter = Iterator() // Applying toIterable method val result = iter.toIterable // Displays output println(result) } } |
Stream()
Here, an empty Stream is returned from an empty-iterator.
Recommended Posts:
- Scala Iterator seq() method with example
- Scala Iterator next() method with example
- Scala Iterator min() method with example
- Scala Iterator max() method with example
- Scala Iterator sum() method with example
- Scala Map iterator method with example
- Scala Iterator zip() method with example
- Scala Iterator map() method with example
- Scala Iterator take() method with example
- Scala Iterator hasDefiniteSize() method with example
- Scala Iterator toList() method with example
- Scala Iterator indexWhere() method with example
- Scala Iterator duplicate() method with example
- Scala Iterator size() method with example
- Scala Iterator find() 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.



