Get the length of a string in Java
Description
The following code shows how to get the length of a string.
Example
/*from w w w . ja v a 2 s .c o m*/
public class Main {
public static void main(String[] argv) {
String stra = "Hello World from java2s.com";
String strb = new String();
System.out.println("Length of stra is " + stra.length());
System.out.println("Length of strb is " + strb.length());
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »