String Concatenation vs StringBuilder Performance Benchmark
This single Java class benchmark, shows impressively that the penalty for using StringBuilder instead of regular String concatenation can be around 5x ! Many static code analyzers like PMD / SonarQube deceptively claim the opposite. This assumption might be a vestige from the pre Java 5 era. Indeed some developers even concatenate compile time constants ( static final ) using StringBuilder. Although be warned , when it comes to using effectively non-final variables inside the concatenation, StringBuilder will drastically outperform the regular String concatenation by several orders of magnitude. Effectively non-final variables are references that are not fixed. On the other hand effectively final values do not necessarily need be prefixed with the " final " keyword but they could be , which differentiates them from effectively non-final variables, that cannot be prefixed with the " final " keyword without causing a compilation error. To state it clear &