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:
3. Observe that the output is displayed in the console as shown below:
Download this project:
Click here to download this project containing 'LengthMethodDemo' class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
How to use charAt( ) method will be explained in the next post.
No comments:
Post a Comment