How to Initialize int or Integer array in declaration?

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

Source code
public class InitializeIntArrayExample {
    public static void main(String[] args) {
        /* Declare and Initialize int Array */
        int intArray[] = {10, 20, 30};
        
        System.out.println("Print value of int[]");
        /* Print value of array */
        for (int i : intArray) {
            System.out.println(i);
        }
        
        /**
         * Declare and Initialize Integer Array.
         * Integer can hold `null` values.
         */
        Integer integerArray[] = {10, 20, null};
        
        System.out.println("Print value of Integer[]");
        for (Integer i : integerArray) {
            System.out.println(i);
        }
    }
}

Output
Print value of int[]
10
20
30
Print value of Integer[]
10
20
null

References
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?
How to Initialize boolean or Boolean array in declaration?

0 comments :