VOOZH about

URL: https://www.geeksforgeeks.org/scala/scala-immutable-treeset-count-method/

⇱ Scala immutable TreeSet count() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Scala immutable TreeSet count() method

Last Updated : 19 Apr, 2020
In Scala immutable TreeSet class, the count() method is utilized to count the number of elements in the TreeSet that satisfies a given predicate.
Method Definition: def count(p: (A) => Boolean): Int Return Type: It returns the count the number of elements in the TreeSet that satisfies a given predicate.
Example #1:
Output:
TreeSet(1, 2, 3, 4, 5)
Number of even element in the TreeSet: 2
Example #2:
Output:
TreeSet(1, 2, 3, 4, 5)
Number of odd element in the TreeSet: 3
Comment
Article Tags:

Explore