Home »
Scala
SortedMap tail() Method in Scala
By IncludeHelp Last updated : November 14, 2024
Map is a collection that stores its elements as key-value pairs, like a dictionary. SortedMap is a special type of map in which elements are sorted in ascending order.
SortedMap tail() Method
tail() method in Scala is used to print all elements of the sortedMap instead of the first element of the sorted map.
Syntax
sortedMap.tail
Parameters
This method does not accept any parameter.
Return Type
It returns a map that contains all elements of the sortedMap instead of the first one.
Example 1
Program to illustrate the working of tail method in Scala
import scala.collection.immutable.SortedMap
object myObject {
def main(args: Array[String]): Unit = {
val mySortedMap = SortedMap("scala" -> 5, "JavaScript" -> 6, "Ruby" -> 8)
val last = mySortedMap.tail
println("The tail of the sortedMap is " + last)
}
}
Output
The tail of the sortedMap is TreeMap(Ruby -> 8, scala -> 5)