/** * Returns a stream consisting of the elements of this stream that aren't * null. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * @return the new stream */ public S nonNull() { return filter(Objects::nonNull); }
/** * Returns a stream consisting of the elements of this stream that don't * match the given predicate. * * <p> * This is an <a href="package-summary.html#StreamOps">intermediate * operation</a>. * * @param predicate a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * predicate to apply to each element to determine if it should be * excluded * @return the new stream */ public S remove(Predicate<? super T> predicate) { return filter(predicate.negate()); }
/** * Returns an {@link Optional} describing the first element of this stream, * which matches given predicate, or an empty {@code Optional} if there's no * matching element. * * <p> * This is a short-circuiting terminal operation. * * @param predicate a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * predicate which returned value should match * @return an {@code Optional} describing the first matching element of this * stream, or an empty {@code Optional} if there's no matching * element * @throws NullPointerException if the element selected is null * @see #findFirst() */ public Optional<T> findFirst(Predicate<? super T> predicate) { return filter(predicate).findFirst(); }
/** * Returns an {@link Optional} describing some element of the stream, which * matches given predicate, or an empty {@code Optional} if there's no * matching element. * * <p> * This is a short-circuiting terminal operation. * * <p> * The behavior of this operation is explicitly nondeterministic; it is free * to select any element in the stream. This is to allow for maximal * performance in parallel operations; the cost is that multiple invocations * on the same source may not return the same result. (If a stable result is * desired, use {@link #findFirst(Predicate)} instead.) * * @param predicate a <a * href="package-summary.html#NonInterference">non-interfering </a>, * <a href="package-summary.html#Statelessness">stateless</a> * predicate which returned value should match * @return an {@code Optional} describing some matching element of this * stream, or an empty {@code Optional} if there's no matching * element * @throws NullPointerException if the element selected is null * @see #findAny() * @see #findFirst(Predicate) */ public Optional<T> findAny(Predicate<? super T> predicate) { return filter(predicate).findAny(); }