Scala SortedSet init() method with example Last Updated : 03 Nov, 2019 Comments Improve Suggest changes Like Article Like Report 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.immutable.SortedSet // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedSet val s1 = SortedSet(1, 2, 3, 4, 5) // Applying init method val result = s1.init // Display output println(result) } } Output: TreeSet(1, 2, 3, 4) Example #2: Scala // Scala program of init() // method import scala.collection.immutable.SortedSet // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedSet val s1 = SortedSet(16, 22, 3, 41, 51) // Applying init method val result = s1.init // Display output println(result) } } Output: TreeSet(3, 16, 22, 41) Comment More infoAdvertise with us Next Article Scala SortedSet init() method with example G gopaldave Follow Improve Article Tags : Scala Scala-Method scala-collection Similar Reads Scala SortedSet find() method with example The find() method is utilized to find the first element of the SortedSet 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 SortedSet which satisfies the given predicate. Example #1: Scala // Sc 1 min read Scala SortedSet -() method with example The -() method is utilized to creates a new SortedSet with a given element removed from the SortedSet. Method Definition: def -(elem: A): SortedSet[A] Return Type: It returns a new SortedSet with a given element removed from the SortedSet. Example #1: Scala // Scala program of -() // method import s 1 min read Scala SortedSet +() method with example The +() method is utilized to create a new SortedSet with an additional element unless the element is already present. Method Definition: def +(elem: A): SortedSet[A] Return Type: It returns a new SortedSet with an additional element unless the element is already present. Example #1: Scala // Scala 1 min read Scala Set init() method with example 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 de 1 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 Like