Home Tutorial Java StringExamples java.lang.String.trim()

 
 

java.lang.String.trim()
Posted on: March 22, 2005 at 12:00 AM
trim() is a string class method in Java that removes all the whitespaces as well as ASCII control characters.

trim() is a string class method in Java that removes all the whitespaces as well as ASCII control characters. String.trim() method removes leading and trailing whitespace(blank spaces) of the string. Just go through the example given below...

a simple example of trim method:

public class StringTrim {

public static void main(String[] args) {

String test = " trim method Remove all spaces. ";

System.out.println("**"+test+"**");

System.out.println("**"+test.trim()+"**");

 //.trim() method will remove the spaces

}

}

the output is:

**trim method Remove all spaces. **
**trim method Remove all spaces.**

Related Tags for java.lang.String.trim():


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.