ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

SortedMap empty() Method in Scala with Example

In this problem, we will learn about empty() method of SortedMap class. It is used to empty the given sortedMap. We will learn about empty() method with examples.
Submitted by Shivang Yadav, on December 20, 2020

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 empty() Method

SortedMap empty() method in Scala is used to convert the given sortedMap to an empty one i.e. delete all elements of SortedMap.

Syntax:

SortedMap_Name.empty

Parameter: The method does not accept any parameters.

Return: It returns a SortedMap which is empty.

Example: Program to illustrate the working of empty method

// Program to illustrate the working of empty() method in scala

import scala.collection.SortedMap

object myObject {
    def main(args: Array[String]) {
        val mySortedMap = SortedMap("scala" -> 5, "JavaScript" -> 6, "Ruby" -> 8)
        println("Sorted Map: " + mySortedMap)
        
        val emptySortedMap = mySortedMap.empty
        println("Empty Sorted Map: " + emptySortedMap)
    }
}

Output:

Sorted Map: TreeMap(JavaScript -> 6, Ruby -> 8, scala -> 5)
Empty Sorted Map: TreeMap()
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

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.