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

后端 未结 11 897
后悔当初
后悔当初 2020-11-27 18:23

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?

11条回答
  •  北海茫月
    2020-11-27 18:50

    This is probably not faster, and definitely not very readable. So, for the sake of colorful solutions...

    int i = array.length()-1;
    for(; i > -1 && array[i]; i--);
    return i==-1
    

提交回复
热议问题