哪里是数组的length属性界定? [英] Where is array's length property defined?
问题描述
我们可以确定的的ArrayList&LT的长度; E>
使用它的公共方法尺寸()
,像
We can determine the length of an ArrayList<E>
using its public method size()
, like
ArrayList<Integer> arr = new ArrayList(10);
int size = arr.size();
同样,我们可以判断一个数组的长度
使用对象长度
属性
String[] str = new String[10];
int size = str.length;
而的ArrayList
的尺寸()
方法是在的ArrayList 内部定义code>类,哪里是
阵列
定义?
Whereas the size()
method of ArrayList
is defined inside the ArrayList
class, where is this length
property of Array
defined?
推荐答案
数组在Java中的特殊对象,他们有一个名为一个简单的属性长度
是最后
。
Arrays are special objects in java, they have a simple attribute named length
which is final
.
有一个数组中没有类定义(你不能在任何的.class文件中找到),他们是语言本身的一部分。
There is no "class definition" of an array (you can't find it in any .class file), they're a part of the language itself.
数组类型的成员都是如下:
10.7. Array Members
The members of an array type are all of the following:
- 的
公共
最后
字段长度
,其中包含该阵列的元件的数量。长度
可能是正数或零。 -
的
公共
方法克隆
,这将覆盖同名类中的方法对象
并没有抛出检查异常。数组类型的克隆
方法的返回类型T []
是T []
。
- The
public
final
fieldlength
, which contains the number of components of the array.length
may be positive or zero. The
public
methodclone
, which overrides the method of the same name in classObject
and throws no checked exceptions. The return type of theclone
method of an array typeT[]
isT[]
.
多维数组的克隆是浅浅的,这就是说,它创建只有一个新的数组。子阵列共享的。
A clone of a multidimensional array is shallow, which is to say that it creates only a single new array. Subarrays are shared.
资源:
- JLS - Arrays
这篇关于哪里是数组的length属性界定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!