String.trim() has the following syntax.
public String trim()
In the following code shows how to use String.trim() method.
/*from w ww . j av a 2s .co m*/ 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.