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 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) } } |
chevron_right
filter_none
Output:
Set(5, 6, 8, 9)
Example #2:
// 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) } } |
chevron_right
filter_none
Output:
Set()
Recommended Posts:
- Scala Map toSet() method with example
- Scala SortedMap toSet() method with example
- Scala Iterator max() method with example
- Scala Iterator sum() method with example
- Scala Map iterator method with example
- Scala Iterator seq() method with example
- Scala Iterator min() method with example
- Scala Iterator map() method with example
- Scala Iterator zip() method with example
- Scala Iterator next() method with example
- Scala Iterator take() method with example
- Scala Iterator nonEmpty() method with example
- Scala Iterator indexWhere() method with example
- Scala Iterator exists() method with example
- Scala Iterator sameElements() 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.



