Java String: length() Method
public int length()
The length() method is used to get the length of this string. The length is equal to the number of Unicode code units in the string.
Java Platform: Java SE 8
Syntax:
length()
Return Value: the length of the sequence of characters represented by this object.
Return Value Type: int
Pictorial presentation of Java String length() Method
Example: Java String length() Method
The following example shows the usage of java String() method.
public class Example {
public static void main(String[] args)
{
String str = "example.com";
// Get the length of str.
int len = str.length();
System.out.println();
System.out.println("The string length of '"+str+"' is: "+len);
System.out.println();
}
}
Output:
The string length of 'example.com' is: 11
Java Code Editor :
Previous:lastIndexOf Method
Next:matches Method
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/java-tutorial/string/string_length.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics