Concatenating strings vs. StringBuilder 2 – Text blocks, Locales, Numbers & Math
JDK 11 JDK 11 produces the following bytecode for concatViaPlus(): Figure 1.13 – JDK 11 bytecode of concatViaPlus() We immediately observe a big difference here. This time, the concatenation is accomplished via a call to invokedynamic (this is a dynamic call) which acts as a delegator for our code. Here,…
20, Jul 2023
Concatenating strings vs. StringBuilder – Text blocks, Locales, Numbers & Math
12. Concatenating strings vs. StringBuilder Check out the following plain string concatenation: String str1 = “I love”;String str2 = “Java”;String str12 = str1 + ” ” + str2; We know that the String class is immutable (a created String cannot be modified). This means that creating str12 requires an intermediary…