Java 去除String 中空格

>str.trim(); //去掉首尾空格
>str.replace(" ",""); //去除所有空格,包括首尾、中间
>str.replaceAll(" ", ""); //去掉所有空格,包括首尾、中间
>str.replaceAll(" +","");  //去掉所有空格,包括首尾、中间
>str.replaceAll("\\s*", ""); //可以替换大部分空白字符, 不限于空格 ;
>ps:\\s* 可以匹配空格、制表符、换页符等空白字符的其中任意一个。
posted @ 2021-02-04 18:04  FlowLiver  阅读(429)  评论(0)    收藏  举报