Java trim () method
trim () method is used to remove the head and tail string of whitespace.
grammar
public String trim()
parameter
no
return value
Whitespace string head and tail removed.
Examples
public class Test { public static void main(String args[]) { String Str = new String(" www.w3big.com "); System.out.print("原始值 :" ); System.out.println( Str ); System.out.print("删除头尾空白 :" ); System.out.println( Str.trim() ); } }
The above program execution results:
原始值 : www.w3big.com 删除头尾空白 :www.w3big.com