donturner donturner - 9 days ago 4
Java Question

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

I have a boolean array in java:

boolean[] myArray = new boolean[10];


What's the most elegant way to check if all the values are true?

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