.length
is an array property. .length()
is a method for the class String
(look here).
When you are looping, you are looping for the length of the array using people.length
.
But when you are using people[i].length()
, you are accessing the string at that position of the array, and getting the length of the string, therefore using the .length()
method in the String
class.
However, just to confuse you more, a String
at its core is just an array of char
s (like this: char[]
). One could make the argument that .length
should work as well, considering it is an array of characters, however, it is a class and that is the reason .length
will not work. Showing empty parameters shows it's a method, and showing no parameters shows that it's a property (like a static
variable in a class).