尽管使用正则表达式会给性能带来 一些 影响,但它不应该那么糟糕。
注意, 每次 调用 时 ,using
String.replaceAll()都会编译正则表达式。
您可以通过显式使用
Pattern对象来避免这种情况:
Pattern p = Pattern.compile("[,. ]+");// repeat only the following part:String output = p.matcher(input).replaceAll("");还要注意,使用
+而不是
*避免替换空字符串,因此也可以加快处理过程。



