Scala ListSet count() method with Example
Last Updated :
15 Feb, 2023
In Scala ListSet, count() method is utilized to count the number of elements of the listSet which satisfy a stated predicate.
Method Definition: def count(p: (A) => Boolean): ListSet[A] Return Type: It returns the count of number of elements of the listset which satisfy the given predicate.
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 .count( _ > 2 )
println(result)
}
}
|
Example 2:
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 .count( _ < 1 )
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...