You can tell the JVM to optimize concat operations with the following:
This flag allows the JVM to optimize the use of StringBuilder instances – in particular those StringBuilders which are created by the compiler when we use the concat operation like:
String concatted = “a “ + “concat”;
The javac compiler translates this into a number of append operations on a StringBuilder object. When we enable the OptimizeStringConcat flag, the JIT compiler will optimize the creation of StringBuilder by itself.
Default is false until 7u4, where it’s enabled by default.
If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your insights will help the entire 10+ million java developer community to develop one standard source of documentation for all the JVM arguments.