Scala Iterator toIterable() method with example Last Updated : 03 Jun, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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) } } Output: Stream(3, ?) Here, a Stream is returned from the stated iterator. Example : Scala // 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) } } Output: Stream() Here, an empty Stream is returned from an empty-iterator. Comment More infoAdvertise with us Next Article Scala Iterator toArray() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Scala Iterator toList() method with example The toList() method belongs to the concrete value members of the AbstractIterable class and is defined in the TraversableOnce and GenTraversableOnce classes. It converts a traversable or iterator to a list but it doesn't terminates for infinite-sized collections. Method Definition: def toList: List[ 1 min read Scala Iterator toArray() method with example The toArray() method belongs to the concrete value member of the class Abstract iterator. It is utilized to convert the stated collection to an array. Method Definition: def toArray: Array[A] Return Type: It returns an array from the elements of the iterator. Example #1: Scala // Scala program of to 1 min read Scala Iterator take() method with example The take() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to select the first n elements of the stated iterator. Method Definition: def take(n: Int): Iterator[A] Where, n is the number of element to take from the given iterator. Return Type: It returns the 2 min read Scala Iterator toSet() method with example The toSet() method belongs to the concrete value member of the class Abstract Iterator. It is defined in the class IterableOnceOps. Method Definition: def toSet[B >: A]: immutable.Set[B] Return Type: It returns a set from the stated collection. Example #1: Scala // Scala program of toSet() // met 1 min read Scala Iterator toSeq() method with example The toSeq() method belongs to the concrete value member of the class Abstract Iterator. It is equivalent to the Seq method but this method is more faster. Method Definition: val result = iter.toSeq Return Type: It returns the stated collection as a sequence. Example #1: Scala // Scala program of toS 1 min read Scala Iterator toBuffer() method with example The toBuffer() method belongs to the concrete value members of the Class AbstractIterator. It is defined in the classes TraversableOnce and GenTraversableOnce. It employs the contents of the stated traversable or iterator to produce a new mutable buffer. It won't end for infinite-sized collections. 1 min read Like