Scala Stack toString() method with example Last Updated : 03 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack(1, 2, 3, 4, 5) // Print the stack println(s1) // Applying toString method val result = s1.toString // Display output print("String representation of the stack object: " + result) } } Output: Stack(1, 2, 3, 4, 5) String representation of the stack object: Stack(1, 2, 3, 4, 5) Example #2: Scala // Scala program of toString() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating stack val s1 = Stack(5, 2, 13, 7, 1, 3) // Print the stack println(s1) // Applying toString method val result = s1.toString // Display output print("String representation of the stack object: " + result) } } Output: Stack(5, 2, 13, 7, 1, 3) String representation of the stack object: Stack(5, 2, 13, 7, 1, 3) Comment More infoAdvertise with us Next Article Scala Stack toString() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Set toString() method with example 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 G 1 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 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 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 Int toString() method with example The toString() method is utilized to return the string representation of the specified value. Method Definition: def toString(): String Return Type: It returns the string representation of the specified value. Example #1: Scala // Scala program of Int toString() // method // Creating object object G 1 min read Like