Possible Duplicate:
Java – Array’s length property
String.length() vs Array.length
I’m currently in my AP Computer Science class in high school and I came across this in my reading.
From what I understand, .length() is a method used for strings, but why isn’t .length() a method when applied on arrays? I understand that they’re different objects, but why didn’t Java just make another method for finding the length of arrays?
I appreciate any response I get. Thanks!
Arrays are defined in the Java Language Specification #10.7. In particular:
I can’t answer why this approach was chosen by the language designers.
Interestingly, it was already the case in the Oak specifications, which is the ancestor of Java.