Consider this snippet -
String a = "hello" , b = null, c = "guru";
boolean value = Stream
.of(a, b, b.substring(2),c)
.allMatch(x -> x != null);
System.out.println(value);
This results in NPE. It seems to be doing b.substring(2) and since b is null, NPE is thrown.
Why is this condition evaluated? The second expression b is null and hence evaluates to false.
So, allMatch will be false regardless of the truth values of the subsequent operations. In that case, why is it trying to evaluate b.substring(2)?
This article and this article claim that it may not evaluate all the expressions if not necessary for determining the result. That clearly does not seem to be the case here.
Prior to Java 7 -
if(b != null && b.substring(2) != null)
this would not throw NPE because b!= null is false and it would return false there itself.
So, can we say that Streams.allMatch is not an exact equivalent of the above Java code snippet?