Scala Map init() method with example
Last Updated :
13 Aug, 2019
The init() method is utilized to delete the last element of the map. It will return all the elements of the Map except the last one.
Method Definition: def init: Map[A, B]
Return Type: It returns all the elements of the map except the last one.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = Map( "geeks" - > 5 , "for" - > 3 , "cs" - > 2 )
val result = m 1 .init
println(result)
}
}
|
Output:
Map(geeks -> 5, for -> 3)
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = Map( "geeks" - > 5 )
val result = m 1 .init
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...