有没有方便的方法可以从Java字符串中去除任何前导或尾随空格?类似这样的东西:
String myString = " keep this ";
String stripppedString = myString.strip();
System.out.println("no spaces:" + strippedString);
结果:
no spaces:keep this
myString.replace(" ","")
将会替换keep和this之间的空格。
String.strip
**,回答了这个问题。 - Naman