Inspectopedia
 
2024.3

Non-constant 'String' can be replaced with 'StringBuilder'

Warning
New
Last modified: 03 December 2024

Reports variables declared as java.lang.String that are repeatedly appended to. Such variables could be declared more efficiently as java.lang.StringBuffer or java.lang.StringBuilder.

Example:

Such a loop can be replaced with:

Or even with:

Use the option to make this inspection only report when the variable is appended to in a loop.