You are correct in your presumptions that most IntelliJ inspections encourage you to do things in a "better" way.
However, this is not always the case. Especially where some inspections work "both ways" -> you'll have to exercise your own judgement about what is "better".
In this case, if you start with a normal concatenated string:
return "count: " + count + "\n";
There are a few inspections available - put cursor on "count: "
and hit alt-enter:
- Replace '+' with String.format()
- Replace '+' with StringBuilder.append()
- Replace '+' with java.text.MessageFormat.format()
If you choose option (2), you get this:
return new StringBuilder().append("count: ").append(count).append("\n").toString();
Now, you can use alt-enter again to choose "Replace StringBuilder with String" reverse the change.
In this case, you have discovered an inspection / refactoring that is bi-directional: it works both ways. Other refactorings (such as "Encapsulate") work only one way.
As for what is "better" - you have to weigh up the performance of StringBuilder
versus readability and simplicity, and make that judgement yourself - IntelliJ is just providing handy inspections to assist you ;)