Skip to content

Conversation

@benelog
Copy link
Contributor

@benelog benelog commented Sep 13, 2018

String.replaceAll () compiles the regular expression each time it is called.

   public String replaceAll(String regex, String replacement) {
        return Pattern.compile(regex).matcher(this).replaceAll(replacement);
    }

It is suggested in javadoc that it is efficient to reuse the pattern, so I modified it accordingly.

If a pattern is to be used multiple times, compiling it once and reusing it will be more efficient than invoking this method each time.

@wumpz
Copy link
Collaborator

wumpz commented Sep 13, 2018

You are right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants