Scala Mutable SortedSet sum() method
Last Updated :
26 Mar, 2020
In Scala mutable collections, sum() method is utilized to find the sum of all the elements of the SortedSet.
Method Definition: def sum: A
Return Type: It returns the sum of all the elements of the SortedSet.
Example #1:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 40 , 10 , 2 , 3 )
val result = s 1 .sum
println(result)
}
}
|
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet( 2 , 6 , 5 , 8 )
val result = s 1 .sum
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...