text:
1, both spaces removed
str.trim()
2, remove all spaces ①
replace(" ", "")
3, remove all spaces ②
replaceAll(" +","")
4, to replace most blank characters, \ S which can match any spaces, tabs, page breaks, etc. a whitespace
replaceAll("\\s*", "")
5, the code to remove spaces
public String remove(String resource,char ch) { StringBuffer buffer=new StringBuffer(); int position=0; char currentChar; while(position<resource.length()) { currentChar=resource.charAt(position++); if(currentChar!=ch) buffer.append(currentChar);
}
return buffer.toString(); }
Reference blog:
JAVA in strips spaces - Alamps - blog Park
https://www.cnblogs.com/alamps/archive/2012/04/27/2473694.html