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 program of count() // method import scala.collection.immutable._// Creating object object GfG { // Main method def main(args:Array[String]) { // Creating litset val m1 = ListSet(1, 2, 3, 4, 5, 7) // Applying filter method val result = m1.count(_>2) // Displays output println(result) } } |
chevron_right
filter_none
Output:
4
Example 2:
// Scala program of count() // method import scala.collection.immutable._// Creating object object GfG { // Main method def main(args:Array[String]) { // Creating litset val m1 = ListSet(1, 2, 3, 4, 5, 7) // Applying filter method val result = m1.count(_<1) // Displays output println(result) } } |
chevron_right
filter_none
Output:
0
Recommended Posts:
- Scala ListSet sum() method with example
- Scala ListSet max() method with example
- Scala ListSet min() method with example
- Scala ListSet filterNot() method with example
- Scala ListSet product() method with example
- Scala ListSet isEmpty() method with Example
- Scala ListSet filter() method with example
- Scala ListSet size() method with example
- Scala ListSet find() method with example
- Scala ListSet exists() method with example
- Scala ListSet takeWhile() method with example
- Scala Listset apply() method with examples
- ListSet in Scala
- Scala Set count() method with example
- Scala Map count() method with example
- Scala TreeSet count() method with example
- Scala Iterator count() method with example
- Scala SortedSet count() method with example
- Scala SortedMap count() method with example
- Scala BitSet count() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

