Share on Google+Share on Google+

java.lang.String.trim()

Advertisement
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.**

Advertisements

Advertisement

Posted on: March 22, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.