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