• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About array in Java

 
C Law
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic