public static < T > boolean xMatch ( final Stream < T > stream , final int num , final Predicate < ? super T > c ) { return stream . filter ( t -> c . test ( t ) ) . collect ( java . util . stream . Collectors . counting ( ) ) == num ; }
Check that there are specified number of matches of predicate in the Stream