java的:基本数组 - 它们是初始化? [英] java: primitive arrays -- are they initialized?
本文介绍了java的:基本数组 - 它们是初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我用一个声明,我的code像
If I use a statement in my code like
int[] a = new int[42];
则初始化数组什么特别? (例如,0)我好像记得这是什么地方,但记录我不知道该怎么寻找。
Will it initialize the array to anything in particular? (e.g. 0) I seem to remember this is documented somewhere but I am not sure what to search for.
推荐答案
目前的 15.10数组创建前pressions 的JLS说:
...]被创建指定长度的一维阵列,并且该阵列的每个组件被初始化为默认值
[...] a single-dimensional array is created of the specified length, and each component of the array is initialized to its default value
在 4.12.5变量的初始值它说:
有关键入 INT
,默认值是零,也就是 0
。
For type
int
, the default value is zero, that is,0
.
这篇关于java的:基本数组 - 它们是初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文