Home > Back-end >  Why to obtain the length of the string in the Java STR. Length (), access to the array length. The l
Why to obtain the length of the string in the Java STR. Length (), access to the array length. The l

Time:04-08

First of all, the array is a container object, which contains a fixed number of values of the same type, once an array is created, its length is fixed, the length of the length of the array can be used as the final instance variables, therefore, the length can be seen as an array of attribute, once the array is created, its size is fixed


Behind a String of data structure is a char array, so there's no need to define an unnecessary attributes (because this property has provided in char values), and C, Java char array is not equal to the String, while the internal mechanism of the String is a char array,



In-depth analysis of length and the length of the Java ()


First of all, character arrays and strings are objects, character array at the time of creation, length is confirmed, so you can use length attribute said its length, the string nature is also a character array, there is no need to use this attribute indicates that the length, encapsulates a method, then the source code is as follows:

Public int length () {
The return value. The length & gt;> Coder ();
}

The size () method, is a way to set the List;


Length - an array of attributes;

Length (), String method;

The size () - a collection of methods;

  • Related