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 predicate used.
Return Type :It returns the number of elements satisfying the predicate p.
Here, only two elements satisfies the stated predicate so, two is returned.