哪里是数组的length属性界定? [英] Where is array's length property defined?

查看:122
本文介绍了哪里是数组的length属性界定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以确定的的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 类,哪里是阵列定义?

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 field length, which contains the number of components of the array. length may be positive or zero.
  • The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions. The return type of the clone method of an array type T[] is T[].

多维数组的克隆是浅浅的,这就是说,它创建只有一个新的数组。子阵列共享的。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆