Scala Mutable SortedMap transform() method with example
Last Updated :
04 May, 2020
The transform() method is utilized to transform the elements of the SortedMap into a mutable SortedMap.
Method Definition: def transform(f: (K, V) => V): SortedMap.this.type
Return Type: It transforms all the elements of the SortedMap and returns them into a mutable SortedMap.
Example #1:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 2 - > "cs" )
val result = m 1 .transform((key, value) => value.toUpperCase)
println(result)
}
}
|
Output:
Map(2 -> CS, 3 -> GEEKS, 4 -> FOR)
Example #2:
import scala.collection.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 4 - > "for" )
val result = m 1 .transform((key, value) => value.toUpperCase)
println(result)
}
}
|
Output:
Map(3 -> GEEKS, 4 -> FOR)
Share your thoughts in the comments
Please Login to comment...