I have a stream and would like to check if all match a filter. If all match, return true
.
But, if the stream is empty, I\'d like to return false>
If you are OK with losing your characteristics and parallelism, this for example:
public static boolean validate(Stream stream) {
Iterator it = stream.iterator();
if (!it.hasNext()) {
return false;
}
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false)
.peek(System.out::println)
.allMatch(x -> x.contains("a"));
}