Advertisement
public int length()
// Program to find the total length of a String.
class StringLen
{
public static void main(String[] ar)
{
String str1= new String("01234567");
System.out.println("First String is " + str1);
System.out.println("Length of first String is "+ str1.length());
System.out.println();
String str2= new String("String Chapter");
System.out.println("Second String is " + str2);
System.out.println("Length of second String is "+ str2.length());
}
}
First String is 01234567
Length of first String is 8
Second String is String Chapter
Length of second String is 14
Advertisement
// Program to find the length of an empty String object
class StringLen
{
public static void main(String[] ar)
{
String str1= new String();
System.out.println("String contains : " + str1);
System.out.println("Length of the String is "+ str1.length());
System.out.println();
str1 = "Today is Tuesday";
System.out.println("String after its initialization : " + str1);
System.out.println("Length of the String is "+ str1.length());
}
}
String contains :
Length of the String is 0
String after its initialization : Today is Tuesday
Length of the String is 16
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement