• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt about Array length ..

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sujit Kurtadikar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sujit Kurtadikar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic