Scala Mutable SortedSet init() method
In Scala mutable collections, SortedSet 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:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 1 , 2 , 3 , 4 , 5 )
val result = s 1 .init
println(result)
}
}
|
Output:
TreeSet(1, 2, 3, 4)
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 16 , 22 , 3 , 41 , 51 )
val result = s 1 .init
println(result)
}
}
|
Output:
TreeSet(3, 16, 22, 41)
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...