The toString() method is utilized to return a string consisting of all the elements of the set.
Method Definition: def toString(): String
Return Type: It returns a string consisting of all the elements of the set.
Example #1:
// Scala program of toString() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(1, 2, 3, 4, 5) // Applying toString method val result = s1.toString // Display output println(result) } } |
chevron_right
filter_none
Output:
Set(5, 1, 2, 3, 4)
Example #2:
// Scala program of toString() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(41, 12, 23, 43, 1, 72) // Applying toString method val result = s1.toString // Display output println(result) } } |
chevron_right
filter_none
Output:
Set(1, 41, 12, 72, 43, 23)
Recommended Posts:
- Scala Iterator toString() method with example
- Scala Map toString() method with example
- Scala String toString() method with example
- Scala Queue toString() method with example
- Scala Char toString() method with example
- Scala Float toString() method with example
- Scala SortedSet toString() method with example
- Scala Stack toString() method with example
- Scala SortedMap toString() method with example
- Scala TreeSet toString() method with example
- Scala Int toString() method with example
- Scala Mutable SortedMap toString() method with example
- Overriding toString() method in Scala
- Scala Mutable SortedSet toString() method
- Scala immutable TreeSet toString() method
- Scala Set &() method with example
- Scala Set dropRight() method with example
- Scala Set equals() method with example
- Scala Set drop() method with example
- Scala Set dropWhile() 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.

