What is the most elegant way to check if all values in a boolean array are true? What is the most elegant way to check if all values in a boolean array are true? arrays arrays

What is the most elegant way to check if all values in a boolean array are true?


public static boolean areAllTrue(boolean[] array){    for(boolean b : array) if(!b) return false;    return true;}


Arrays.asList(myArray).contains(false)


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.