String.concat is faster than the + operator if you are concatenating two strings... Although this can be fixed at any time and may even have been fixed in java 8 as far as I know.

The thing you missed in the first post you referenced is that the author is concatenating exactly two strings, and the fast methods are the ones where the size of the new character array is calculated in advance as str1.length() + str2.length(), so the underlying character array only needs to be allocated once.

Using StringBuilder() without specifying the final size, which is also how + works internally, will often need to do more allocations and copying of the underlying array.

If you need to concatenate a bunch of strings together, then you should use a StringBuilder. If it's practical, then precompute the final size so that the underlying array only needs to be allocated once.

Answer from Matt Timmermans on Stack Overflow
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › › api › java.base › java › lang › invoke › StringConcatFactory.html
StringConcatFactory (Java SE 17 & JDK 17)
October 20, 2025 - Facilitates the creation of optimized String concatenation methods, that can be used to efficiently concatenate a known number of arguments of known types, possibly after type adaptation and partial evaluation of arguments. Typically used as a bootstrap method for invokedynamic call sites, to support the string concatenation feature of the Java Programming Language.
🌐
Baeldung
baeldung.com › home › java › java string › concatenating strings in java
Concatenating Strings in Java | Baeldung
May 8, 2025 - Although synchronization is often synonymous with thread safety, it’s not recommended for use in multithreaded applications due to StringBuffer’s builder pattern. While individual calls to a synchronized method are thread safe, multiple calls are not. Next up is the addition operator (+). This is the same operator that results in the addition of numbers and is overloaded to concatenate when applied to Strings.
Discussions

java - Most efficient way to concatenate Strings - Stack Overflow
I was under the impression that StringBuffer is the fastest way to concatenate strings, but I saw this Stack Overflow post saying that concat() is the fastest method. I tried the 2 given examples i... More on stackoverflow.com
🌐 stackoverflow.com
dart - Optimizations of "+" operand for strings in JDK 17 - Stack Overflow
We know that in JDK8 and below, strings using a plus sign for concatenation will be compiled into StringBuilder for performance optimization, but after JDK9, it will be implemented using the java.l... More on stackoverflow.com
🌐 stackoverflow.com
java - String concatenation performance: + vs StringBuilder - Stack Overflow
I'm not convinced that this is correct, I have been doing some benchmarking in a project I'm involved with and have found that the StringBuilder method is still faster. I am using Java 17, I think it is important to size the StringBuilder to the size of the String expected. More on stackoverflow.com
🌐 stackoverflow.com
String Concatenation with (+)

Imagine a class:

import java.util.UUID;
public class StringThing {
public static void main(String[] args) {
var x= UUID.randomUUID().toString();
var y=UUID.randomUUID().toString();
var z=x+y;
System.out.println(z);
}
}

Running javap -c StringThing gives:

Compiled from "StringThing.java"
public class StringThing {
public StringThing();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: invokestatic #7 // Method java/util/UUID.randomUUID:()Ljava/util/UUID;
3: invokevirtual #13 // Method java/util/UUID.toString:()Ljava/lang/String;
6: astore_1
7: invokestatic #7 // Method java/util/UUID.randomUUID:()Ljava/util/UUID;
10: invokevirtual #13 // Method java/util/UUID.toString:()Ljava/lang/String;
13: astore_2
14: aload_1
15: aload_2
16: invokedynamic #17, 0 // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
21: astore_3
22: getstatic #21 // Field java/lang/System.out:Ljava/io/PrintStream;
25: aload_3
26: invokevirtual #27 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
29: return
}

Note line 16. This is from Java 17.

More on reddit.com
🌐 r/javahelp
5
2
September 22, 2023
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › String.html
String (Java SE 17 & JDK 17)
April 21, 2026 - The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.
🌐
Baeldung
baeldung.com › home › java › java string › string concatenation in java
String Concatenation in Java | Baeldung
January 8, 2024 - In this article, we provided a quick overview of string concatenation in Java. Additionally, we discussed in detail the use of concat() and the “+” operator to perform string concatenations.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › concat
Java String concat() - Concatenate Strings | Vultr Docs
November 19, 2024 - Chain the concat() method to concatenate more than two strings. ... String string1 = "Java"; String string2 = " is"; String string3 = " awesome!"; String result = string1.concat(string2).concat(string3); System.out.println(result); Explain Code
Find elsewhere
🌐
W3Schools
w3schools.com › Java › java_strings_concat.asp
Java Strings Concatenation
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... The + operator can be used between strings to combine them.
🌐
Delft Stack
delftstack.com › home › howto › java › java append to string
How to Append Strings in Java Efficiently | Delft Stack
February 2, 2024 - The concat(String str) method concatenates some specific Strings into the end of the string. It allocates the char[] of length, equal to the combined length of two Strings. This method copies String data into that string and creates a new String ...
🌐
Medium
medium.com › javarevisited › 5-effective-string-practices-you-should-know-e9a75811b123
String concatenation in Java: Best practices | Javarevisited
March 31, 2022 - You should use + it when there’s no loop involved. Use StringBuilder when concatenation happens in a loop. Let’s say we need to concat 100 strings. We could do it like this. ... A humble place to learn Java and Programming better.
🌐
iO Flood
ioflood.com › blog › java-string-concatenation
Java String Concatenation | Complete Method Guide
July 8, 2024 - Let’s dive in and start mastering how to add to a string in Java! The simplest way to concatenate strings in Java is using the ‘+’ operator.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-optimize-string-concatenation-in-java
How to Optimize String Concatenation in Java? - GeeksforGeeks
July 23, 2025 - Concat(String str) method concatenates the specified String to the end of this string. This method appends the specified string at the end of the given string and returns the combined string.
Top answer
1 of 1
1

Taking @Holger's advice, I checked the bytecode for following code:

public class StringBM {
    public String toStringPlus(String a) {
        return "{a:" + a + ", b:" + ", c: " + "}";
    }

    public String toStringBuilder(String a) {
        StringBuilder sb = new StringBuilder(100);
        return sb.append("{a:").append(a)
                .append(", b:")
                .append(", c:")
                .append("}")
                .toString();
    }
}

For toStringPlus, I get

  public java.lang.String toStringPlus(java.lang.String);
    descriptor: (Ljava/lang/String;)Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=2, args_size=2
         0: aload_1
         1: invokedynamic #7,  0              // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String;
         6: areturn

for toStringBuilder:

public java.lang.String toStringBuilder(java.lang.String);
    descriptor: (Ljava/lang/String;)Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=3, locals=3, args_size=2
         0: new           #11                 // class java/lang/StringBuilder
         3: dup
         4: bipush        100
         6: invokespecial #13                 // Method java/lang/StringBuilder."<init>":(I)V
         9: astore_2
        10: aload_2
        11: ldc           #16                 // String {a:
        13: invokevirtual #18                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        16: aload_1
        17: invokevirtual #18                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        20: ldc           #22                 // String , b:
        22: invokevirtual #18                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        25: ldc           #24                 // String , c:
        27: invokevirtual #18                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        30: ldc           #26                 // String }
        32: invokevirtual #18                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        35: invokevirtual #28                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        38: areturn

The + version simply invokes dynamic function makeConcatWithConstants.
Whereas the StringBuilder version has to do it the 'honest' way.
I guess we can see why is + faster now.

🌐
Java67
java67.com › 2015 › 05 › 4-ways-to-concatenate-strings-in-java.html
4 ways to concatenate Strings in Java [Example and Performance] | Java67
Anyway, this article is not just about + operator but also about other ways to concatenate multiple Strings. There are four ways to do this, apart from the + operator, we can use StringBuffer, StringBuilder, and concat() method from java.lang.String ...
🌐
DZone
dzone.com › coding › java › jdk 9/jep 280: string concatenations will never be the same
JDK 9/JEP 280: String Concatenations Will Never Be the Same
February 4, 2019 - Contrasting the differences in -verbose output from javap for the HelloWorldStringConcat class's main(String) method when compiled with JDK 8 (AdoptOpenJDK) and JDK 11 (Oracle OpenJDK) is shown next. I have highlighted some key differences. Classfile /C:/java/examples/helloWorld/classes/dustin/examples/HelloWorldStringConcat.class Last modified Jan 28, 2019; size 625 bytes MD5 checksum 3e270bafc795b47dbc2d42a41c8956af Compiled from "HelloWorldStringConcat.java" public class dustin.examples.HelloWorldStringConcat minor version: 0 major version: 52 .
🌐
Medium
marian-caikovski.medium.com › strings-how-java-17-is-worse-and-better-than-java-8-59f4088504a3
Strings — how Java 17 is worse and better than Java 8 | by Marian C. | Medium
December 6, 2021 - Overall, strings are the most used and critical data type in web development. Most of time users either read or type something. JSONs and HTML pages produced by Java servers are made through concatenating strings.
🌐
Medium
medium.com › @nagarjun_nagesh › maximizing-performance-in-java-string-concatenation-c588a7a125e8
Maximizing Performance in Java String Concatenation | by Nagarjun (Arjun) Nagesh | Medium
June 26, 2024 - While the + operator is convenient and readable for small-scale concatenation, using StringBuilder explicitly is recommended for scenarios involving concatenation of multiple strings, especially within loops or performance-sensitive code. By understanding these nuances and following best practices outlined in "Effective Java," developers can optimize string concatenation to improve application performance and efficiency.
🌐
Reddit
reddit.com › r/javahelp › string concatenation with (+)
r/javahelp on Reddit: String Concatenation with (+)
September 22, 2023 -

Hello,

I was checking StringBuilder and StringBuffer classes and read that String "+" operator uses one of them. I could not find when and why and how it decides to use which one. Did anybody got curious and found the answer before?

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#:~:text=The%20Java%20language,Language%20Specification.

Here is the link from Java docs.