Empty arrays automatically initialize contents?

后端 未结 5 1740
滥情空心
滥情空心 2021-01-16 13:35

How come

int alone;
System.out.println(alone);

Gives errors but

 int[] arr = new int[1];
 System.out.println(arr[0]);
         


        
5条回答
  •  無奈伤痛
    2021-01-16 14:04

    Yes, for primitive type number arrays, it initializes with 0, for boolean[], it initializes with false, for char[], it initializes with NULL(ASCII value 0) and for objects [] including String[] its initializes with null.

提交回复
热议问题