java: primitive arrays — are they initialized?

前端 未结 4 586
耶瑟儿~
耶瑟儿~ 2020-12-09 16:50

If I use a statement in my code like

int[] a = new int[42];

Will it initialize the array to anything in particular? (e.g. 0) I seem to reme

4条回答
  •  独厮守ぢ
    2020-12-09 17:21

    At 15.10 Array Creation Expressions the JLS says

    [...] a single-dimensional array is created of the specified length, and each component of the array is initialized to its default value

    and at 4.12.5 Initial Values of Variables it says:

    For type int, the default value is zero, that is, 0.

提交回复
热议问题