Match and Count Sequence Data

Viewed 22

I'm trying to match and count the data in the sequence data.What I have done so far as below:

val fruits = Seq("apple", "PEAR", "Pear")
fruits.exists(_.equalsIgnoreCase("pear"))

from here, how do we count the output as 2?

1 Answers

exists returns the boolean value so it will tell whether particular keyword exists or not in collection.

To find the count,

fruits.count(_.equalsIgnoreCase("pear"))
Related