Sobes.tech
Junior — Middle

What will be the result of calling the allMatch method on an empty data stream?

sobes.tech AI

Answer from AI

In Java, the allMatch method returns true for an empty stream. This is because allMatch checks that all elements satisfy a condition, and for an empty set, the statement "all elements satisfy the condition" is considered true by definition (universal quantifier rule).

Example:

Stream<Integer> emptyStream = Stream.empty();
boolean result = emptyStream.allMatch(x -> x > 0); // result will be true