ADVERTISEMENT
ADVERTISEMENT

SortedMap tail() Method in Scala with Example

Here, we will learn about the tail() method in Scala. The tail() method prints all elements of the sortedMap instead of the first elements. Here, we see syntax and examples to understand it.
Submitted by Shivang Yadav, on January 24, 2021

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

Parameter: This method does not accept any parameter.

Return: 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]) {
        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)
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.