Usage:
This flag allows the compiler to optimize the construction of Strings by StringBuilder.
Since:
Starting from JDK 6.
Examples:
This will instruct JVM to disable the optimization of the construction of Strings by StringBuilder:
-XX:-OptimizeStringConcat
Description:
When the flag is enabled, it allows the JVM to optimize the use of StringBuilder objects. The StringBuilder objects that are created by the java compiler (javac) when writing code.
Given the following code:
new StringBuilder().append(value).toString()
Or
new StringBuilder().append(new StringBuiler().append(value).toString()).toString()
Where value is a String, char or an int
Instead of constantly allocating memory for a new concatenation operation, JVM will try to calculate the total number of characters of each concatenation object to allocate memory only once.
In other words, if we call the “append()” operation 10 times on a 10 character string. Then the creation of the character array will happen once and will be 100 characters.
It also transform expression like “new StringBuilder().append(Integer.toString(int))” to “new StringBuilder().append(int)”
Default Value:
This option is enabled by default.
Arguments related:
PrintOptimizeStringConcat
Related Posts:
Edit your Comment