Java String trim() 方法
描述
此方法返回去除了字符串前导和后续空白的副本。
语法
这是该方法的语法 −
public String trim()
参数
这是参数的详细信息 −
- NA
 
返回值
- 返回去除前导和尾部空白的该字符串的副本,如果该字符串没有前导或尾部空白,则返回该字符串。
 
示例
import java.io.*;
public class Test {
   public static void main(String args[]) {
      String Str = new String("   Welcome to Tutorialspoint.com   ");
      System.out.print("Return Value :" );
      System.out.println(Str.trim() );
   }
}
这将产生以下结果:
输出
Return Value :Welcome to Tutorialspoint.com
极客教程