The map.last
function in Scala is used to get the reference of the last element, or key-value pair, in the map.
Figure 1 shows a visual representation of the map.last
function.
The following module is required in order to use the function:
scala.collection.mutable.Map
map_name.last
// where the map_name is the name of the map.
This function does not require a parameter.
The map.last
function returns the reference to the set’s last element, or key-value pair.
empty
, it throws a Error
.The following code shows how to use the map.last
function in Scala.
import scala.collection.mutable.Mapobject Main extends App {//creating map with valuesval map = scala.collection.mutable.Map(1 -> "Tom",2 -> "Alsvin",3 -> "Eddie")//map_1 elements and lengthprintln("The map elements: " + map);println("The map last element: " + map.last);}