Counting how many times any of the items appear in a Scala List -


i have following list:

val list = list("this", "this", "that", "there", "here", "their", "where") 

i want count how many times "this" or "that" appears. can like:

 list.count(_ == "this") + list.count(_ == "that") 

is there concise way of doing this?

you can count more 1 occurrence @ time. no need call count twice.

scala> list.count(x => x == "this" || x == "that") res4: int = 3 

Comments