如何检查布尔数组是否包含所有真值?

时间:2015-11-11 23:51:48

标签: java arrays boolean

我有以下布尔数组:

boolean booleanArray[]  = new boolean [size];

如何检查数组中的所有值是否为真,并将此信息用于另一个布尔值“allTrue”?

我需要将它用于while循环,即:

while(alltrue){
            keepgoing();
        }

我想做一个for循环检查每个值,但只返回一个值,我不知道如何与其余值进行比较,以了解它们是否相等。
提前谢谢。

1 个答案:

答案 0 :(得分:1)

将变量初始化为false,如果找到allTrue,请将false设置为break并将boolean allTrue = true; for (boolean b : booleanArray) { if (!b) { allTrue = false; break; } } 设置为循环。

$("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(3)").after("<td><i class='fa fa-plus-square-o'></i></td>");

$("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(4)").click(function()
{
    if ($("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(4) > i").hasClass("fa fa-plus-square-o")){
        $(this).replaceWith("<td><i class='fa fa-minus-square-o'></i></td>");
    }
    if ($("#test > div > div.row-fluid > table > tbody > tr > td:nth-child(4) > i").hasClass("fa fa-minus-square-o")){
        $(this).replaceWith("<td><i class='fa fa-plus-square-o'></i></td>");
    }
});