Why is Streams.allMatch(in Java8) trying to evaluate all the expressions even if the value can be determined midway?
问题 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