Scala SortedMap toSet() method with example
The toSet() method is utilized to display a set from the Scala SortedMap.
Method Definition: def toSet: Set[A]
Return Type: It returns a set from the stated SortedMap.
Example #1:
// Scala program of toSet() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a SortedMap val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 4 - > "for" ) // Applying toSet method val result = m 1 .toSet // Displays output println(result) } } |
chevron_right
filter_none
Output:
Set((3, geeks), (4, for))
Example #2:
// Scala program of toSet() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a SortedMap val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 2 - > "cs" ) // Applying toSet method val result = m 1 .toSet // Displays output println(result) } } |
chevron_right
filter_none
Output:
Set((2, cs), (3, geeks), (4, for))
Recommended Posts:
- Scala Map toSet() method with example
- Scala Iterator toSet() method with example
- Scala SortedMap max() method with example
- Scala SortedMap take() method with example
- Scala SortedMap get() method with example
- Scala SortedMap contains() method with example
- Scala SortedMap min() method with example
- Scala SortedMap count() method with example
- Scala SortedMap drop() method with example
- Scala SortedMap init() method with example
- Scala SortedMap filterKeys() method with example
- Scala SortedMap equals() method with example
- Scala SortedMap size() method with example
- Scala SortedMap apply() method with example
- Scala SortedMap addString() 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.