Summary of length and length() issues in Java

Is there a length() method for arrays in Java? Does String have a length() method?

Arrays have no length() method.
Array variables are reference types. Arrays can also be regarded as objects. Each element in the array is equivalent to a member variable of the object. The array itself is an object, and the object in Java is in the heap. Therefore, whether the array saves the original type or other object types, the array object itself is stored in the heap. But there is no class for creating arrays in Java, so arrays do not have a length() method
. Does array have a length attribute? Yes
,
but arrays are not defined by classes in Java, so which class of Java is this attribute in? Where does this attribute of these arrays come from? I don’t understand
the description of the article I saw a few days ago.

String is a string class and has a length() method.
In JavaScript, the length of the string is obtained through the length attribute, which is easy to confuse with Java.

For an explanation of why there is no array class in java, click here to view the article :

Guess you like

Origin blog.csdn.net/qq_40694640/article/details/112644407