Java trim() method: remove the spaces before and after the string

trim()

Example

public static void main(String[] args){
    String strCom = "JAVA编程词典";  //定义字符串
    String str = strCom.trim();  //去除字符串前后的空格
    System.out.println("未去除前后空格的字符串:"+strCom);
    System.out.println("去除前后空格后的字符串:"+str);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>