You are here: Home / Topics / length() function example in Java String

length() function example in Java String

Filed under: Java on 2023-08-23 06:58:27

// Program to explain the following String function :
// int length()

class  Mlength
{
public static void main( String args[ ] )
{
 char ch[ ] = { 'J', 'A', 'V', 'A' };
 String s1 = new String( ch );

 System.out.println( " String = " + s1 );
 System.out.println( " Length = " + s1.length() );
 System.out.println( " Length = " + "Java Programming Examples".length() );
}
}


Output:

 String = JAVA
 Length = 4
 Length = 25

 

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.