Scala ListSet sum() method with example
Last Updated :
15 Feb, 2023
In Scala ListSet, sum() method is utilized to add all the elements of the stated listSet.
Method Definition: def sum(num: math.Numeric[B]): B Return Type: It returns the sum of all the elements of the listSet.
Example 1:
Scala
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val m 1 = ListSet( 1 , 2 , 3 , 4 , 5 , 7 )
val result = m 1 .sum
println(result)
}
}
|
Example 2:
Scala
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val m 1 = ListSet( 1 , - 2 )
val result = m 1 .sum
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...