aspose file tools*
The moose likes Beginning Java and the fly likes length variable in arrays.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "length variable in arrays...." Watch "length variable in arrays...." New topic
Author

length variable in arrays....

vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
class testArrayLength
{
private static int [] arr = new int[10];
public static void main(String ar[])
{
System.out.println(arr.length);
}
}

the output is 10...

please someone help me from where this variable length came from the API... how is the arr.length works..??? and that too it is length and not LENGTH... all are of lower case.. please help.. thanks in advance...


Regards,
vignesh
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
length is a final field associated with arrays.
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
when arr.length works it means that length is associated with arrays.. but how and where do the length variable come from??? pls help me...
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Arrays are objects, but there is no class definition associated with it. They inherit some methods from Object and when created the length field is initialized.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Array's are not in the API, but are described in the Java Language Specification.

"The array's length is available as a final instance variable length." (Ref: Section 10.3 - Array Creation).

Also see Section 10.7 - Array Members.
[ April 05, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
kalps ganvir
Greenhorn

Joined: Mar 29, 2006
Posts: 8
length is benificial var that will return u the length of array .getting !!
so explore ur skills of using it. instead of unnessesarily findng its history.




'MAN IS CREATURE WHO TAKES MORE INTREST IN TEACHING INSTEAD OF LEARNING NEW THINGS'

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: length variable in arrays....