Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
String methods - trim() and length() - Testingpool

String methods – trim() and length()

I this post, we will discuss about the string methods – trim() and length().

Let’s understand them one by one with examples.

trim():

The method trim() is used to remove leading and trailing white spaces from the input String.

e.g. Suppose, If we have a string ”   Name  “.  After using trim , String will remove the whitespaces i.e.  “Name”.

public class ExampTrim {
	public static void main(String[] args) {

		String val1 = "     How are you?  ";
		System.out.println("After trimming the string - "+val1.trim() +"??");
	}
}
Output: After trimming the string – How are you???

length():

It is used to find out the no. of character in the string ,that is nothing but the length of the string.

public class ExampTrim {
	public static void main(String[] args) {

		String val1 = "Hello World";
		System.out.println("The length of the string is - "+val1.length());
	}
}
Output: The length of the string is – 11
Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. August 6, 2015

    […] int length() […]