How to Initialize float or Float array in declaration?

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

Source code
public class InitializeFloatArrayExample {
    public static void main(String[] args) {
        /* Declare and Initialize float Array */
        float[] floatArray1 = {10.1f, 20.2f, 30.3f};
        
        System.out.println("Print value of float[]");
        /* Print value of array */
        for (float f : floatArray1) {
            System.out.println(f);
        }
        
        /**
         * Declare and Initialize Float Array.
         * Float can hold `null` values.
         */
        Float floatArray2[] = {10.1f, 20.2f, null};
        
        System.out.println("Print value of Float[]");
        /* Print value of array */
        for (Float f : floatArray2) {
            System.out.println(f);
        }
    }
}

Output
Print value of float[]
10.1
20.2
30.3
Print value of Float[]
10.1
20.2
null

References
How to Initialize int or Integer 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 :