Scala ListSet count() method with Example Last Updated : 15 Feb, 2023 Comments Improve Suggest changes Like Article Like Report 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 // Scala program of count() // method import scala.collection.immutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating listset val m1 = ListSet(1, 2, 3, 4, 5, 7) // Applying filter method val result = m1.count(_>2) // Displays output println(result) } } Output:4 Example 2: Scala // Scala program of count() // method import scala.collection.immutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating listset val m1 = ListSet(1, 2, 3, 4, 5, 7) // Applying filter method val result = m1.count(_<1) // Displays output println(result) } } Output:0 Comment More infoAdvertise with us Next Article Scala ListSet count() method with Example I IshwarGupta Follow Improve Article Tags : Scala Scala-Method scala-collection Similar Reads Scala Iterator count() method with example The count() method belongs to the concrete value members of the class Abstract Iterator. It is defined in the class IterableOnceOps. It counts the number of elements in the stated collection which satisfy the given predicate. Method Definition : def count(p: (A) => Boolean): Int Where, p is the p 1 min read Scala ListSet sum() method with example 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 // Scala program of sum() // method import scala.collection.immutable._ / 1 min read Scala ListSet size() method with example In Scala ListSet, size() method is utilized to find the number of elements of the stated listSet. Method Definition: def size(): Int Return Type: It returns the number of elements in the stated listSet. Example 1: Scala // Scala program of size() // method import scala.collection.immutable._ // Crea 1 min read Scala Map count() method with example The count() method is utilized to count pair of keys in the Map. Method Definition: def count(p: ((A, B)) => Boolean): Int Return Type: It returns the number of keys present in the map that satisfies the given predicate. Example #1: Scala // Scala program of count() // method // Creating object o 1 min read Scala ListSet find() method with example In Scala ListSet, find() method is utilized to find the first element of the listset that satisfies the given predicate. Method Definition: def find(p: (A) => Boolean): Option[A] Return Type: It returns the first element of the listset which satisfies the given predicate. Example 1: Scala // Scal 1 min read Like