Scala Set count() method with example
Last Updated :
15 Oct, 2019
The count() method is utilized to count the number of elements in the set.
Method Definition: def count(p: (A) => Boolean): Int
Return Type: It returns the number of elements present in the set.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 , 5 )
val result = s 1 .count(z => true )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set()
val result = s 1 .count(z => true )
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...