Java trim() 方法

Java 教程 · 2019-02-09 08:26:43

trim() 方法用于删除字符串的头尾空白符。

语法

public String trim()

参数

返回值

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

实例

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

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

以上程序执行结果为:

原始值 :    www.codercto.com    
删除头尾空白 :www.codercto.com

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Pattern Recognition and Machine Learning

Pattern Recognition and Machine Learning

Christopher Bishop / Springer / 2007-10-1 / USD 94.95

The dramatic growth in practical applications for machine learning over the last ten years has been accompanied by many important developments in the underlying algorithms and techniques. For example,......一起来看看 《Pattern Recognition and Machine Learning》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具