Convert boolean inside if statement

Hello, I am working on a program where I am using a particular logic for a flag, I am declaring a boolean variable, and then making an if statement that executes if the statement and then add value to an array, but I want to alternatively add values to my array. EG I have 1001 I want to add 1 in array1, 0 in both arrays, 0 in both arrays, 1 in array1. This is how I have written this in code. But the problem is that the boolean is always true, it doesn't get flase even after the if statement has executed. This is my code:

for(int i = 0; i < reversedBinaryValue.size(); i++)
        {
            boolean addToSplitOne = true;

            // since arrays are already filled with zeroes, it skips an additional step of
            // filling with zeros
            if(reversedBinaryValue.get(i) == 1)
            {
                // now working with the flag that the bit has been added to splitOne or not
                if(addToSplitOne)
                {
                    binarySplitOne[i] = reversedBinaryValue.get(i);
                    // now set the split to true so the flag is interchanged, and we can add value in split two
                    addToSplitOne = false;

                } // end of if
                else
                {
                    binarySplitTwo[i] = reversedBinaryValue.get(i);

                    // now set the split to false so that we can add value to split one
                    addedToSplitOne = true;
                } // end of else

            } // end of main if

        } // end of for
Was this page helpful?