What is the most elegant way to check if all values in a boolean array are true?
In Java 8, you could do:
boolean isAllTrue = Arrays.asList(myArray).stream().allMatch(val -> val == true);
Or even shorter:
boolean isAllTrue = Arrays.stream(myArray).allMatch(Boolean::valueOf);
Note:You need Boolean[]
for this solution to work. Because you can't have a primitives List.