No, not quite.

Firstly, there's a slight difference in semantics. If a is null, then a.concat(b) throws a NullPointerException but a+=b will treat the original value of a as if it were null. Furthermore, the concat() method only accepts String values while the + operator will silently convert the argument to a String (using the toString() method for objects). So the concat() method is more strict in what it accepts.

To look under the hood, write a simple class with a += b;

public class Concat {
    String cat(String a, String b) {
        a += b;
        return a;
    }
}

Now disassemble with javap -c (included in the Sun JDK). You should see a listing including:

java.lang.String cat(java.lang.String, java.lang.String);
  Code:
   0:   new     #2; //class java/lang/StringBuilder
   3:   dup
   4:   invokespecial   #3; //Method java/lang/StringBuilder."<init>":()V
   7:   aload_1
   8:   invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   11:  aload_2
   12:  invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   15:  invokevirtual   #5; //Method java/lang/StringBuilder.toString:()Ljava/lang/    String;
   18:  astore_1
   19:  aload_1
   20:  areturn

So, a += b is the equivalent of

a = new StringBuilder()
    .append(a)
    .append(b)
    .toString();

The concat method should be faster. However, with more strings the StringBuilder method wins, at least in terms of performance.

The source code of String and StringBuilder (and its package-private base class) is available in src.zip of the Sun JDK. You can see that you are building up a char array (resizing as necessary) and then throwing it away when you create the final String. In practice memory allocation is surprisingly fast.

Update: As Pawel Adamski notes, performance has changed in more recent HotSpot. javac still produces exactly the same code, but the bytecode compiler cheats. Simple testing entirely fails because the entire body of code is thrown away. Summing System.identityHashCode (not String.hashCode) shows the StringBuffer code has a slight advantage. Subject to change when the next update is released, or if you use a different JVM. From @lukaseder, a list of HotSpot JVM intrinsics.

Answer from Tom Hawtin - tackline on Stack Overflow
🌐
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.
🌐
W3Schools
w3schools.com › java › ref_string_concat.asp
Java String concat() Method
Java Examples Java Videos Java ... System.out.println(firstName.concat(lastName)); ... The concat() method appends (concatenate) a string to the end of another string....
🌐
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.
🌐
CodeSignal
codesignal.com › learn › courses › getting-started-with-java › lessons › java-string-magic-understanding-concatenation-operations
Java String Magic: Understanding Concatenation Operations
Greetings, future programmer! Today, we're exploring an essential concept in Java — Concatenation Operations. Concatenation involves joining strings together. We’ll start by defining concatenation and then explore various ways to perform it in Java.
🌐
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.
🌐
CodeGym
codegym.cc › java blog › strings in java › string concatenation in java
String Concatenation in Java
April 1, 2025 - Java String concatenation is an operation to join two or more strings and return a new one. Also, the concatenation operation can be used to cast types to strings. You can concatenate strings in Java in two different ways...
🌐
Medium
medium.com › @AlexanderObregon › beginners-guide-to-java-string-concatenation-1e2fbccda0bc
Beginner’s Guide to Java String Concatenation
March 26, 2024 - String concatenation in Java is ... web applications. At its core, string concatenation is the process of combining two or more strings end-to-end to form a new string....
Top answer
1 of 12
655

No, not quite.

Firstly, there's a slight difference in semantics. If a is null, then a.concat(b) throws a NullPointerException but a+=b will treat the original value of a as if it were null. Furthermore, the concat() method only accepts String values while the + operator will silently convert the argument to a String (using the toString() method for objects). So the concat() method is more strict in what it accepts.

To look under the hood, write a simple class with a += b;

public class Concat {
    String cat(String a, String b) {
        a += b;
        return a;
    }
}

Now disassemble with javap -c (included in the Sun JDK). You should see a listing including:

java.lang.String cat(java.lang.String, java.lang.String);
  Code:
   0:   new     #2; //class java/lang/StringBuilder
   3:   dup
   4:   invokespecial   #3; //Method java/lang/StringBuilder."<init>":()V
   7:   aload_1
   8:   invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   11:  aload_2
   12:  invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   15:  invokevirtual   #5; //Method java/lang/StringBuilder.toString:()Ljava/lang/    String;
   18:  astore_1
   19:  aload_1
   20:  areturn

So, a += b is the equivalent of

a = new StringBuilder()
    .append(a)
    .append(b)
    .toString();

The concat method should be faster. However, with more strings the StringBuilder method wins, at least in terms of performance.

The source code of String and StringBuilder (and its package-private base class) is available in src.zip of the Sun JDK. You can see that you are building up a char array (resizing as necessary) and then throwing it away when you create the final String. In practice memory allocation is surprisingly fast.

Update: As Pawel Adamski notes, performance has changed in more recent HotSpot. javac still produces exactly the same code, but the bytecode compiler cheats. Simple testing entirely fails because the entire body of code is thrown away. Summing System.identityHashCode (not String.hashCode) shows the StringBuffer code has a slight advantage. Subject to change when the next update is released, or if you use a different JVM. From @lukaseder, a list of HotSpot JVM intrinsics.

2 of 12
105

Niyaz is correct, but it's also worth noting that the special + operator can be converted into something more efficient by the Java compiler. Java has a StringBuilder class which represents a non-thread-safe, mutable String. When performing a bunch of String concatenations, the Java compiler silently converts

String a = b + c + d;

into

String a = new StringBuilder(b).append(c).append(d).toString();

which for large strings is significantly more efficient. As far as I know, this does not happen when you use the concat method.

However, the concat method is more efficient when concatenating an empty String onto an existing String. In this case, the JVM does not need to create a new String object and can simply return the existing one. See the concat documentation to confirm this.

So if you're super-concerned about efficiency then you should use the concat method when concatenating possibly-empty Strings, and use + otherwise. However, the performance difference should be negligible and you probably shouldn't ever worry about this.

Find elsewhere
🌐
Javatpoint
javatpoint.com › string-concatenation-in-java
String Concatenation in Java - javatpoint
June 25, 2018 - Java Program to swap two string variables without using third or temp variable.
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-concat-examples
Java String concat() Method with Examples - GeeksforGeeks
The concat() method in Java is used to append one string to another and returns a new combined string. It does not modify the original string since strings are immutable. ... class GFG { public static void main(String args[]) { // String ...
Published   April 7, 2026
🌐
TechVidvan
techvidvan.com › tutorials › java-string-concatenation
Java String concat() Method with Examples - TechVidvan
February 17, 2025 - Concatenation is combining two or more strings to form a new string by appending the next string to the end of the previous strings. In Java, two strings can be concatenated using the + or += operator or the concat() method, defined in the ...
🌐
Educative
educative.io › answers › how-to-concatenate-strings-in-java
How to concatenate strings in Java - Educative.io
String concatenation combines multiple strings into a single new string. It’s useful in creating file paths, personalizing content, constructing URLs, bioinformatics (DNA/protein sequences), etc.
🌐
ThoughtCo
thoughtco.com › concatenation-2034055
Understanding the Concatenation of Strings in Java
May 18, 2025 - Concatenation in the Java programming language describes the operation of joining two strings together.
🌐
LabEx
labex.io › tutorials › java-java-string-concatenation-117956
Mastering String Concatenation in Java | LabEx
The simplest method of combining strings in Java is by using the + operator. The + operator is overloaded to work with strings. Follow the code block below to see how to concatenate strings using the + operator.
🌐
Scientech Easy
scientecheasy.com › home › blog › string concatenation in java
String Concatenation in Java - Scientech Easy
May 29, 2025 - But when you finish the form, you see your complete name as a single string. This is a real-time use of string concatenation. In Java, a string can be concatenated with two or more strings or a string with a number or symbol to display information as per requirements.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_concat.htm
Java - String concat() Method
The Java String concat() method is used to concatenate the specified string to the end of this string. Concatenation is the process of combining two or more strings to form a new string.
🌐
Programiz
programiz.com › java-programming › library › string › concat
Java String concat()
The concat() method concatenates (joins) two strings and returns it. class Main { public static void main(String[] args) { String str1 = "Java"; String str2 = "Programming"; // concatenate str1 and str2
🌐
Net Informations
net-informations.com › java › string › concat.htm
Java String concat() Method
The Java String Concat(String str) method serves the purpose of concatenating the provided String to the end of the original string.