java.lang.String.trim()


 

java.lang.String.trim()

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.

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

Ads