Scala Set init() method with example Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The init() method is utilized to find all the elements of the set except the last one. Method Definition: def init: Set[A] Return Type: It returns all the elements of the set except the last one. Example #1: Scala // Scala program of init() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(1, 2, 3, 4, 5) // Applying init method val result = s1.init // Display output println(result) } } Output: Set(5, 1, 2, 3) Example #2: Scala // Scala program of init() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set(16, 22, 3, 41, 51) // Applying init method val result = s1.init // Display output println(result) } } Output: Set(41, 22, 3, 16) Comment More infoAdvertise with us Next Article Scala Set init() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Scala-Set +1 More Similar Reads Scala Stack init() method with example In Scala Stack class, the init() method is utilized to return a new stack that consists of all the elements except the last one. Method Definition: def init: Stack[A] Return Type: It returns a new stack that consists of all the elements except the last one. Example #1: Scala // Scala program of init 2 min read Scala TreeSet init() method with example In Scala TreeSet class, the init() method is utilized to return a new TreeSet that consists of all the elements except the last one. Method Definition: def init: TreeSet[A] Return Type: It returns a new TreeSet that consists of all the elements except the last one. Example #1: Scala // Scala program 2 min read Scala Set find() method with example The find() method is utilized to find the first element of the set that satisfies the given predicate if present. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element of the set which satisfies the given predicate. Example #1: Scala // Scala program 1 min read Scala Int self() method with example The self() method is utilized to return the same value which has been specified. Method Definition: (Value).selfReturn Type: It returns true the same value which has been specified. Example 1: Scala // Scala program of Int self() // method // Creating object object GfG { // Main method def main(args 1 min read Scala SortedSet init() method with example The init() method is utilized to find all the elements of the SortedSet except the last one. Method Definition: def init: SortedSet[A] Return Type: It returns all the elements of the SortedSet except the last one. Example #1: Scala // Scala program of init() // method import scala.collection.immutab 1 min read Like