Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Delivering the MVP Forum

Brendan Passey
Brendan Passey
999 Points

stringArray.length is not a method?

Hey guys, So when I need to find the length of a string I would use the string.length() method. However when finding the length of an array (how many indexes) instead we just use Array.length without using the brackets (). I can only assume this means we aren't using a method in this case. What's going on here? The quiz at the very end of java objects informed me "it is indeed just a public field". I'm not sure what "it" is refering to. Clarification please and thankyou.

1 Answer

Steven Parker
Steven Parker
231,269 Points

It looks like "it" was talking about "length", which is a public field that every array has. It's not a method like a string has, so it's a good idea to know what kind of thing you are getting the length of to do it the right way. :wink: