The length of a string is the number of characters that it contains. To obtain this value, call the length() method, shown here:
int length()
Example to print the length of string "Java Guides".
public class LengthExample {
public static void main(String[] args) {
String str = new String("Java Guides");
int length = str.length();
System.out.println(" length of the string '" + str + "' is :: " + length);
}
}
Output:
length of the string 'Java Guides' is:: 11
Reference
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course