I’m preparing for the OCP exam.
In a book there’s the following review question the answer to which turned out to be the allMatch
terminal operation:
var s = Stream.generate(() -> "meow");
var match = s.allMatch(String::isEmpty);
System.out.println(match);
It executes and prints false
My question is how does Java can determine that exactly all the elements match the predicate while the stream is infinite and supposed to hang?