Java : How to set the flag value in a array loop
<p>This is my below mehod for Validation .</p>

<pre><code>public boolean validateData(Bagform[] bagdata) {
    boolean flag = false;
    int length = bagdata.length;

    if (length == 2) {
        for (int i = 0; i &lt; bagdata.length; i++) {
            if (bagdata[i].getCallType() == null) {
                flag = true;
            }
        }
    }
    else {
        flag = true;
    }
    return flag;
}
</code></pre>

<p>In this basically i am checking that if the getCallType()  is not  null for any of the values in the array .</p>

<p>If its not null , then its a valid data , so i am setting the flag to true .
(Please see the code above ) </p>

<p>But for me , i am getting the  flag value still  as false  ( Even though the getCallype() is not null ) </p>

<p>Please help me .</p>
