• 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

length in array

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
what is the scope of the variable length in an array!
i just want to know how is it declared in the library
and how does it work
can any one help me out!
thanks
siva
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The length variable is simply an instance variable declared within the array object. When you create an array, that variable is set to whatever size you indicate.
 
sivaramp pratapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, but why cant we assign or change this variable, other than
when initializing the array!
its set when we initialize an array!
why can't i assign some thing like
array.length= some number;
at the same time, this instance variable can be accessed thru the instance it got created,
is it declared final, (i dont think so, since it keeps changing whenever the size of the array changes or a new object of the same array is created
whenever the size of the array changes?)
and to add to the question, is it declared public or protected..
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Array sizes cannot be changed once you instantiate the array. So, why would you want to change the length variable? You would possibly break code that uses the length for any purpose, such at looping.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Array Members 10.7
 
sivaramp pratapa
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,Marlene Miller
that really helps a lot
and i am very much satisfied looking at the url you sent..
and Jeff Bosch has asked me why would i want to change the length variable,
i was just checking whether can we assign any value to that variable or not!
since it is declared as final, as i found out
now there is no question of assigning any value to it..
thanks a lot for all your help folks!
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sivaramp. I guessed you might like to see the JLS spec on this topic. Thank you for letting us know.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic