Scala Set toString() method with example Last Updated : 18 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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) } } Output: Set(5, 1, 2, 3, 4) Example #2: Scala // 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) } } Output: Set(1, 41, 12, 72, 43, 23) Comment More infoAdvertise with us Next Article Scala Set toString() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Scala-Set +1 More Similar Reads Scala Stack toString() method with example In Scala Stack class, the toString() method is utilized to return a string representation of the stack object. Method Definition: def toString(): String Return Type: It returns a string representation of the stack object. Example #1: Scala // Scala program of toString() // method // Import Stack imp 2 min read Scala String toString() method with example The toString() method is utilized to return a string object itself. Method Definition: String toString() Return Type: It returns the string object. Example: 1# Scala // Scala program of toString() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying toS 1 min read Scala SortedSet toString() method with example The toString() method is utilized to return a string consisting of all the elements of the SortedSet. Method Definition: def toString(): String Return Type: It returns a string consisting of all the elements of the SortedSet. Example #1: Scala // Scala program of toString() // method import scala.co 1 min read Scala Set toList() method with example The toList() method is utilized to return a list consisting of all the elements of the set. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the set. Example #1: Scala // Scala program of toList() // method // Creating object object GfG { // Mai 1 min read Scala SortedMap toString() method with example The toString() method is utilized to display a string from the Scala SortedMap. Method Definition: def toString(): String Return Type: It returns a string from the stated SortedMap. Example #1: Scala // Scala program of toString() // method import scala.collection.immutable.SortedMap // Creating obj 1 min read Like