public static < T > int count ( Collection < T > items , Predicate < T > predicate ) { int count = 0 ; if ( ! isEmpty ( items ) ) { for ( T element : items ) { if ( predicate . apply ( element ) ) { count ++ ; } } } return count ; }
Returns the number of elements in a collection matching the given predicate .