62,612
社区成员
发帖
与我相关
我的任务
分享
String str = " ashgslf ";
Pattern p = Pattern.compile("\\s*");
Matcher m =p.matcher(str);
m.replaceAll("");
//str.replaceAll("\\s*","2");
System.out.println(str);
ashgslf
String str = " ashgslf ";
Pattern p = Pattern.compile("\\s*");
Matcher m =p.matcher(str);
m.replaceAll("");
//str.replaceAll("\\s*","2");
System.out.println(m.replaceAll(""));
System.out.println(str.trim());
System.out.println(str.replace(" ", ""));
都能达到效果,你的没生效是你输出的是转化之前的str