String类的trim() 方法

用于删除字符串的头尾空白符。

语法:public String trim()

返回值:删除头尾空白符的字符串。

 

 

public class Test {
    public static void main(String args[]) {
        String Str = new String("    xiaohouzi.com    ");
        System.out.print("原始值 :" );
        System.out.println( Str );

        System.out.print("删除头尾空白 :" );
        System.out.println( Str.trim() );
    }
}

 

执行结果为:原始值 :    xiaohouzi.com

       删除头尾空白 :xiaohouzi.com

posted @ 2018-10-24 15:45  小仙女吖。  阅读(21014)  评论(0编辑  收藏  举报