In java, Strings are objects that belong to class java.lang.String. A string is a sequence of simple characters. We can do many things with the string object like we can find out its length, we can compare it with other string, concatenate with other string.
We can get the length of the string by using the method length() of java.lang.String.
The code of the program is given below:
<html> <head> <title>Getting Length of a String</title> </head>
<body> <h1>Getting Length of a String</h1> <% String s1 = "Length of a String!"; out.println("\"" + s1 + "\"" + " is of " + s1.length() + " characters "); %> </body> </html>
The output of the program is given below:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial