The #6 is just an example.
I completely agree JVM optimizes in a lot of ways.
StringBuffer is way more efficient than normal String concatenation.
Benchmark Mode Cnt Score Error Units
Benchmark.First.stringBuffer thrpt 25 52791,073 ± 196,355 ops/s
Benchmark.First.stringConcat thrpt 25 7355,182 ± 39,284 ops/s
And this is on JDK 12.
For some reason your JDK decided out to replace str concat with stringbuilder.
Look here for more information:
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.