This terminal operation returns whether no elements of this stream match the provided predicate. It may not evaluate the predicate on all elements if not necessary for determining the result, hence, it is a short circuiting operation. If the stream is empty then true
is returned and the predicate is not evaluated.
This terminal-short-circuiting operation of Stream interface, returns 'false' when the very first element matches the provided predicate and terminating the rest of the traversal.
package com.logicbig.example;
import java.util.stream.Stream;
public class NoneMatchExample {
public static void main (String[] args) {
Stream<String> stream = Stream.of("one", "two", "three", "four");
boolean match = stream.noneMatch(s -> s.length() > 0 &&
Character.isUpperCase(s.charAt(0)));
System.out.println(match);
}
}
Output
true
Original Post