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() 方法的效果。
601

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



