File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Array documentation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array documentation" Watch "Array documentation" New topic

Array documentation

Patrick Cicero

Joined: Nov 06, 2002
Posts: 17
In alot of java code examples they show code like
int[] myArray = new int[10]
for(int i = 0; i < myArray.length; i++)
myArray[i] = i+10;
I think I have seen this use of the Array.length field to get the length of an Array even on SUN web pages. But the API documentation does NOT show the Array Class as having a Class field of length, but it must have this field.
Am I totaly messed up or is the API incomplete?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, Patrick!
I believe that the cause of your confusion is understanding what Array is versus what an array of some data type is.
The Array class is a utility class that provides static methods to create and access arrays. Array is not an array of some data type (such as an array of int or String - int[] or String[]).
The interface of an array of some data type is considerably different than the interface of Array. The interface of an array of some data type does provide access to the final length field.
Is this starting to make more or less sense?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Cindy Li

Joined: Oct 31, 2002
Posts: 4
Array Type is literally represented by [].
It is described in the Jave Language Specification, -- 10.7 Array members.
(not in Java 2 Platform API Specs)
Array Type defines a member field 'length' as public final.
Hope that helps.
I agree. Here's the link:
subject: Array documentation
It's not a secret anymore!