String concatenation in loop
Reports String concatenation in loops.
As every String concatenation copies the whole string, usually it is preferable to replace it with explicit calls to StringBuilder.append()
or StringBuffer.append()
.
Example:
After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
StringContatenationInLoop- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Sometimes, the quick-fixes allow you to convert a String
variable to a StringBuilder
or introduce a new StringBuilder
. Be careful if the original code specially handles the null
value, as the replacement may change semantics. If null
is possible, null-safe fixes that generate necessary null-checks are suggested. Also, it's not guaranteed that the automatic replacement will always be more performant.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |