views:

93

answers:

1

Hi everybody. I'm extremely new to java. I'm currently learning by book and have stumbled across the following problem.

I noticed that for example when learning about arrays they mention that you can call "arrayname.length" to get the length of that array. I'm trying to look in the online API documentation to see what public variables/methods is available. The documentation shows a lot of methods but nowhere can I find the .length one.

What am I misunderstanding? How can I track down these "default" methods/variables you can use with each object to see what its default behavior is?

Thanks a lot!

+5  A: 

An array has a final instance variable named length, according to the Java Language Specification.

From Section 10.3: Array Creation:

The array's length is available as a final instance variable length.

Looking in the the Java API Specification for an array isn't going to work here, as the array type is actually just an Object, according to Section 10 of the JLS:

In the Java programming language arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.

Therefore, there is no actually array class in itself. (Other than a representation of an array as an Array class in the Reflection API.)

All the specifics about how arrays work in Java is laid out in the aforementioned Section 10 of the Java Language Specification.

coobird