File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt about Array length .. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt about Array length .." Watch "Doubt about Array length .." New topic
Author

Doubt about Array length ..

Sujit Kurtadikar
Ranch Hand

Joined: Dec 05, 2000
Posts: 68
Array is defined as
int[ ] x = new int[5];
then x.length will give value 5,
what is length? method / data member and if so then of which class (surely it will not method)
regards,
sujit
Shrini Kulkarni
Ranch Hand

Joined: Jan 12, 2001
Posts: 63
For Arrays - "length" is data members which will specify the number of elements in the Array.

"length" can not be a method as it does not use () while being called.


Sun Certified programmer for Java2 platform.<BR>Shri_mk@hotmail.com
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
All arrays are an object of the Array class. length is a data member of that class. It can be a data mamber because this information is set. Try this

Hope This Helps

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Sujit Kurtadikar
Ranch Hand

Joined: Dec 05, 2000
Posts: 68
int [] x = new int[5];
x.getClass().getName() gives [I
if(x instanceof Array) --> this gives error Class Array Not Found
I have checked, class Array is in java.lang.reflect package
what is class for array object and what is length ?
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Eventhough arrays are objects, they are instantiated without the class name, which means they don't belong to any class as such. Since arrays are objects, x instanceof Object returns true.
The java.lang.reflect.Array class provides static methods to dynamically create and access Java arrays. It is for a different purpose.
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Sujit Kurtadikar
Ranch Hand

Joined: Dec 05, 2000
Posts: 68
Dear Ajith,
if x is array, then (x instanceof Object) gives result true.
Now it is clear to me.
Still I have doubt about .length ?
length is member of which class ? It has to be memeber of some class.
x.getClass().getName() gives result [I , what is meaning of [I
sujit
[This message has been edited by Sujit Kurtadikar (edited January 17, 2001).]
[This message has been edited by Sujit Kurtadikar (edited January 17, 2001).]
 
jQuery in Action, 2nd edition
 
subject: Doubt about Array length ..
 
Similar Threads
Array of Strings
what's the meaning of " a[j]++?, thanks
Returning an array
Space complexity of an array of arrays
length Vs length()