Home >>Java String Methods >Java String length() Method
Java length() method in Java String is used to returns the length (empty string is 0) of a specified string.
public int length()
None
Returns - It is used to return An int value which represents the length of the string
public class Lengthexample1
{
public static void main(String[] args)
{
String Name = "HELLOWORLD";
System.out.println(Name.length());
}
}
public class Lengthexample2
{
public static void main(String[] args)
{
String strln1 = "Phptpoint";
if(strln1.length()>0)
{
System.out.println("String is not empty and length is: "+strln1.length());
}
strln1 = "";
if(strln1.length()==0)
{
System.out.println("String is empty now: "+strln1.length());
}
}
}