Java How To Find Length Of String
Today we’re going to show you how to find the length of a string in Java. Fortunately this is very easy.
Answer: to find the length of a string in Java just use the length method like this: len = myString1.length();
That’s it! In Java Strings are objects. The String class has a public method called length() that will return the length of the string as an int. The length is the number of characters in the string. Here is a slightly more complete example.
class Test1 {
public static void main( String args[] ) {
String myString1 = "This is my test string";
int len = myString1.length();
System.out.println("The length of this string is: " + len);
}
}