The init() method is utilized to delete the last element of the SortedMap. It will return all the elements of the SortedMap except the last one.
Method Definition: def init: SortedMap[A, B]
Return Type: It returns all the elements of the SortedMap except the last one.
Example #1:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( "geeks" - > 5 , "for" - > 3 , "cs" - > 2 )
val result = m 1 .init
println(result)
}
}
|
Output:
Map(cs -> 2, for -> 3)
Example #2:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( "geeks" - > 5 )
val result = m 1 .init
println(result)
}
}
|