• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array documentation

 
Patrick Cicero
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Cindy Li
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Array Type is literally represented by [].
It is described in the Jave Language Specification, http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html#25518 -- 10.7 Array members.
(not in Java 2 Platform API Specs)
Array Type defines a member field 'length' as public final.
Hope that helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic