• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

length variable in arrays....

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
length is a final field associated with arrays.
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'

 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic