Efficiently removing specific characters (some punctuation) from Strings in Java?

后端 未结 7 672
青春惊慌失措
青春惊慌失措 2020-12-10 17:14

In Java, what is the most efficient way of removing given characters from a String? Currently, I have this code:

private static String processWord(String x)          


        
7条回答
  •  执念已碎
    2020-12-10 17:33

    Although \\p{Punct} will specify a wider range of characters than in the question, it does allow for a shorter replacement expression:

    tmp = tmp.replaceAll("\\p{Punct}+", "");
    

提交回复
热议问题