Java String.trim()
Syntax
String.trim() has the following syntax.
public String trim()
Example
In the following code shows how to use String.trim() method.
//from w ww . j a va 2s . c om
public class Main {
public static void main(String[] argv) {
String str = " java 2 s.com ";
System.out.println(">"+str+"<");
str = str.trim();
System.out.println(">"+str+"<");
}
}
The code above generates the following result.