Scala Iterator toSeq() method with example Last Updated : 13 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 toSeq() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a Iterator val iter = Iterator(2, 5, 7, 8, 9) // Applying toSeq method val result = iter.toSeq // Displays output println(result) } } Output: Stream(2, ?) So, here a sequence is obtained. Example #2: Scala // Scala program of toSeq() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating an empty Iterator val iter = Iterator() // Applying toSeq method val result = iter.toSeq // Displays output println(result) } } Output: Stream() So, here an empty iterator is obtained as the stated iterator is empty. Comment More infoAdvertise with us Next Article Scala Iterator toList() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads 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 seq() method with example The seq() method belongs to the concrete value members of the class Iterable. It is helpful in visualizing the sequential view of the stated collection. It has a time complexity of O(1). Method Definition: def seq: Iterator[A] Return Type: It returns a sequential view of the iterator. Example : Scal 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 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 size() method with example The size() method belongs to the concrete value members of the class Abstract Iterator. It is defined in the classes IterableOnceOps. It is utilized to find the size of the stated collection. It will not terminate for the infinite sized collection. Method Definition : def size: Int Return Type :It r 1 min read Scala Iterator slice() method with example The slice() method belongs to the concrete value members of the class AbstractIterator. It is defined in the class Iterator. It creates a new iterator for the interval given in the slice. The first value present in the slice indicates the start of the element in the new iterator and the second value 2 min read Like