Ok so I have this code:
public class Test {
public static void main(String[] args) {
String[] people = {"Bob", "Billy", "Jim"};
int sum = 0;
for(int i = 0; i < people.length; i++) {
sum += people[i].length();
}
}
}
My question is why people[i].length()
is .length()
and not .length
. I thought to get the length of an array you use .length
and not .length()
. Do you use .length()
because you are trying to get the length of a string and not an array? P.S. I am a beginner, so this may seem very obvious to you, but it isn't to me.