It's not a secret anymore!
The moose likes Beginning Java and the fly likes About array in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: About array in Java
 
Similar Threads
HI!!!
Cattle Drive Problem 1
length Vs length()
String doubt
Expressions!