Java String 去除中间空格:简单高效的解决方案
可以使用 replaceAll() 方法将中间的空格去掉。代码如下:
String str = 'Hello world';
str = str.replaceAll(' ', '');
System.out.println(str);
输出结果为:
Helloworld
原文地址: https://www.cveoy.top/t/topic/o0ES 著作权归作者所有。请勿转载和采集!
安全问答是一个知识全球问答,包含丰富的问答知识
可以使用 replaceAll() 方法将中间的空格去掉。代码如下:
String str = 'Hello world';
str = str.replaceAll(' ', '');
System.out.println(str);
输出结果为:
Helloworld
原文地址: https://www.cveoy.top/t/topic/o0ES 著作权归作者所有。请勿转载和采集!