trim():去掉字符串首尾的空格。
public static void main(String arg[]){
String a=" hello world ";
String b="hello world";
System.out.println(b.equals(a));
a=a.trim();//去掉字符串首尾的空格
System.out.println(a.equals(b));
}执行结果:a: hello world ,false
a:hello world,true
本文通过一个简单的示例介绍了 Java 中 String 类的 trim() 方法的使用方法。该方法用于去除字符串两端的空白字符,并通过比较 trim() 处理前后字符串的等价性来展示其效果。

716

被折叠的 条评论
为什么被折叠?



