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

查看所有标签

Agile Web Development with Rails 4

Agile Web Development with Rails 4

Sam Ruby、Dave Thomas、David Heinemeier Hansson / Pragmatic Bookshelf / 2013-10-11 / USD 43.95

Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details. Tens of thousands of deve......一起来看看 《Agile Web Development with Rails 4》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具