• Post Reply Bookmark Topic Watch Topic
  • New Topic

args.length  RSS feed

 
ramchander yshetti
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai

public static void main(String args[])
{....
.....

for(int i=0;i<=args.length;i++)


can you tell me args.length(it returns the length of the array)
.length is what it is function or keyword
where it is in api.



.....
...
 
Ganesh Kumar
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ramachander
Length is function which returns an value of the length of the data you have given.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was always thoughts arrayObject.length was actual a property, a public final variable of the "array" class and not a method, as a method requires brackets: ().
[ July 26, 2007: Message edited by: Gavin Tranter ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Syntactically, it's an instance member -- i.e., in the code it looks like a variable. But in reality, it is compiled to a special bytecode which returns the length of an array object; it's not a "real" instance member of the array object.

yathamshetti ramchander -- "length" isn't anywhere in the API because it's not a member of any class that's documented in the API. Instead, it's a feature of the Java language. You learn about it from the language specification, or (more likely) from any introductory Java book.

Don't worry that there are many things like this to learn. There is only one similar feature in all of Java -- one other thing that looks like a member variable, but isn't. That's the static "class" member. You can say, for example, "String.class" to get a java.lang.Class object that represents the class java.lang.String.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!