Profile Image
vishnupriya

What is JVM startup parameter: -XX:-OptimizeStringConcat?

What is JVM startup parameter: -XX:-OptimizeStringConcat? Have you used this JVM arguement before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvmargument

  • xx-optimizestringconcat

  • x-optimizestringconcat

  • JVM startup parameter

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky

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:

 

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvmargument

  • xx-optimizestringconcat

  • x-optimizestringconcat

  • JVM startup parameter