Using 'length( )' method for finding the length of a string

You can use the length( ) predefined method to find out the length of a string.

Example:

String myString1 = "This is a string text";

System.out.println("The length of the text stored in myString1 object is " + myString1.length( ) );

Lets implement this on Eclipse IDE:

1. Create 'LengthMethodDemo' class under any project as shown below:



2. Save and Run the 'LengthMethodDemo' class
3. Observe that the output is displayed in the console as shown below:



Note: The space between the words is also counted by the length( ) predefined method.