Scala Iterator toSet() method with example Last Updated : 26 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a Iterator val iter = Iterator(5, 6, 8, 9) // Applying toSet method val result = iter.toSet // Displays output println(result) } } Output: Set(5, 6, 8, 9) Example #2: Scala // Scala program of toSet() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating an empty Iterator val iter = Iterator() // Applying toSet method val result = iter.toSet // Displays output println(result) } } Output: Set() Comment More infoAdvertise with us Next Article Scala Iterator toSet() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads 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 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 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 to 1 min read Scala Set intersect() method with example The intersect() method is utilized to compute the intersection between two sets. Method Definition: def intersect(that: Set[A]): Set[A] Return Type: It returns a set containing the elements present in both the sets. Example #1: Scala // Scala program of intersect() // method // Creating object objec 1 min read Scala Map toSet() method with example The toSet() method is utilized to display a set from the Scala map. Method Definition: def toSet: Set[A] Return Type: It returns a set from the stated map. Example #1: Scala // Scala program of toSet() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creatin 1 min read Like