Scala Stack toList() method with example Last Updated : 03 Nov, 2019 Comments Improve Suggest changes Like Article Like Report In Scala Stack class, the toList() method is utilized to return a list consisting of all the elements of the stack. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the stack. Example #1: Scala // Scala program of toList() // 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 toList method val result = s1.toList // Display output print("Elements in the list: ") for(elem <- result) print(elem + " ") } } Output: Stack(1, 2, 3, 4, 5) Elements in the list: 1 2 3 4 5 Example #2: Scala // Scala program of toList() // 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) // Print the stack println(s1) // Applying toList method val result = s1.toList // Display output print("Elements in the list: ") for(elem <- result) print(elem + " ") } } Output: Stack(5, 2, 13, 7, 1) Elements in the list: 5 2 13 7 1 Comment More infoAdvertise with us Next Article Scala Set toList() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads 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 Stack toSeq() method with example In Scala Stack class, the toSeq() method is utilized to return a seq consisting of all the elements of the stack. Method Definition: def toSeq: Seq[A] Return Type: It returns a seq consisting of all the elements of the stack. Example #1: Scala // Scala program of toSeq() // method // Import Stack im 2 min read Scala SortedMap toList() method with example The toList() method is utilized to display the elements of the SortedMap in the list. Method Definition: def toList: List[A] Return Type: It returns all the elements of the SortedMap in the list. Example #1: Scala // Scala program of toList() // method import scala.collection.immutable.SortedMap // 1 min read Scala SortedSet toList() method with example The toList() method is utilized to return a list consisting of all the elements of the SortedSet. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the SortedSet. Example #1: Scala // Scala program of toList() // method import scala.collection.im 1 min read Scala Set toSeq() method with example The toSeq() method is utilized to return a seq consisting of all the elements of the set. Method Definition: def toSeq: Seq[A] Return Type: It returns a seq consisting of all the elements of the set. Example #1: Scala // Scala program of toSeq() // method // Creating object object GfG { // Main meth 1 min read Scala Stack toArray() method with example In Scala Stack class, the toArray() is utilized to return an array consisting of all the elements of the stack. Method Definition: def toArray: Array[A] Return Type: It returns an array consisting of all the elements of the stack. Example #1: Scala // Scala program of toArray() // method // Import S 2 min read Like