public static < T > T firstOrNull ( Collection < T > items , Predicate < T > predicate ) { if ( ! isEmpty ( items ) ) { for ( T item : items ) { if ( predicate . apply ( item ) ) { return item ; } } } return null ; }
Returns the first element from a collection that matches the given predicate or null if no matching element is found .