This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes About array in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About array in Java" Watch "About array in Java" New topic
Author

About array in Java

C Law
Greenhorn

Joined: Mar 05, 2006
Posts: 21
Why we use length() to calculate the length of a string,
but "length" to compute the length of an array?

Is the "length" attribute in an array a public instance
variable?

Thanks!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by C Law:
...Is the "length" attribute in an array a public instance variable?

Yes. "The array's length is available as a final instance variable length." (Ref: JLS - Section 10.3.)
[ March 21, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Originally posted by C Law:
Why we use length() to calculate the length of a string,
but "length" to compute the length of an array?


Old naming conventions. We also use size() on java collections including arraylists so don't think the confusion stops at strings and typed arrays.
[ March 21, 2006: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
 
GeeCON Prague 2014
 
subject: About array in Java