Where is Array's Length Property Defined?
When working with an ArrayList, its size can be obtained using the public method size(). Similarly, the length property provides the size of an Array object. However, unlike the size() method defined within the ArrayList class, where is the length property of arrays defined?
Answer:
Arrays in Java are unique objects with a final attribute called length. This property is not defined within any specific class; rather, it is an inherent part of the language itself.
According to the Java Language Specification, an array type has several members, including:
- The public final field length, which contains the number of components of the array.
- The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions.
- All the members inherited from class Object; the only method of Object that is not inherited is its clone method.
Resources:
- JLS - Arrays: https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.7
The above is the detailed content of Where is the `length` Property of Java Arrays Defined?. For more information, please follow other related articles on the PHP Chinese website!