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
202,063 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: