how can i convert stringformat calls to stringformatted?

For this particular code you can use Regex replacement upon pressing ctrl+R in IntelliJ Idea and clicking the .* icon.

enter image description here

  • The Regex (see the demo): String.format\((\".*\")?\, ?(.*)\);
  • The substitution (in the very same demo): $1.formatted\($2\);

I have to remind you multiple reasons not to do that:

  • Replacing such methods just because it is new has no meaning and brings no benefit. The code will not become more maintainable, more readable and not even faster.
  • Are you sure you need this method? The advantage of this method is when the format pattern of the string is built continuously so the formatted method is comfortable because of a direct use. I describe this in my another answer.
  • Regex based replacement is not safe and reliable in such large scale. The Regex itself also heavily depends on the absence of strange characters right in the formatting pattern itself. Otherwise, you spend a lot of time refining the Regex.

A better way to do if you wish so is to find these methods and replace them manually. In such case, do the full-text search using ctrl+shift+F and make the search based on this pattern:


enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top