The length is equal to the number of 16 Unicode code units in the string.
Example:
Common class test {
Public static void main (strinargs []) {
String str 1 = new String(" www . run OOB . com ");
String Str2 = new string ("runoob");
system . out . print(" String str 1 Length:");
system . out . println(str 1 . length());
System.out.print ("Str2 length: ");
system . out . println(str 2 . length());
}
}
The results of the above procedure are as follows:
String Str 1 Length: 14
String Str2 length: 6
Extended data
The Length property is used to find the length of an array.
The length () method is used to find the length of a string.
The size () method is used to calculate the length of a set.
An array is an object container that holds a fixed number of values of a certain type. After an array is created, its length cannot be changed. The length of the array is an available immutable member variable. Therefore, the length is regarded as an attribute of the array.
Arrays can be created in two ways: through expressions.
Array initializer. The length is specify at creation time. You can use arrays to create expressions like the code in the above example. The member type it specifies. The number of layers of the array and the length of at least one layer of the array.
The following statement is still valid when representing the length of a layer.
Baidu Encyclopedia-Length