How to Initialize boolean or Boolean array in declaration?

UPDATED: 25 October 2015
Following excerpt show How you can Initialize boolean or Boolean array in its declaration.

Source code
public class InitializeBooleanArrayExample {
    public static void main(String[] args) {
        /* Declare and Initialize boolean Array */
        boolean[] booleanArray1 = {true, false};
        
        System.out.println("Print value of boolean[]");
        /* Print value of array */
        for (boolean b : booleanArray1) {
            System.out.println(b);
        }
        
        /**
         * Declare and Initialize Boolean Array.
         * Boolean can hold `null` values.
         */
        Boolean booleanArray2[] = {true, false, null};
        
        System.out.println("Print value of Boolean[]");
        /* Print value of array */
        for (Boolean b : booleanArray2) {
            System.out.println(b);
        }
    }
}

Output
Print value of boolean[]
true
false
Print value of Boolean[]
true
false
null

References
How to Initialize int or Integer array in declaration?
How to Initialize float or Float array in declaration?
How to Initialize long or Long array in declaration?
How to Initialize double or Double array in declaration?

0 comments :