That should already be fast - it'll use StringBuilder internally for concatenation. Arguably using StringBuilder explicitly could eliminate the concatenation of empty strings, but it's not likely to make a big difference.

How often are you doing this, anyway? It must be pretty often, for it to be a bottleneck... do you really need to do it that often?

EDIT: For those who are saying "Use StringBuilder, it'll be faster" - consider this code:

public class Test
{
    public static void main(String[] args)
    {
        int x = 10;
        int y = 20;
        int z = 30;
        String foo = x + "," + y + "," + z + ";";
        System.out.println(foo);
    }
}

Compile that, then use javap -c to see what the compiler generates...

Answer from Jon Skeet on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ concatenate-string-to-an-int-value-in-java
Concatenate string to an int value in Java
Here is our int. ... Now, to concatenate a string, you need to declare a string and use the + operator. ... Let us now see another example. import java.util.Random; public class Demo { public static void main( String args[] ) { int val = 3; ...
Discussions

integer - How to concatenate int values in java? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. ... How do i concatenate these values so that i end up with a String that is 10221; please note that multiplying a by 10000, b by 1000.....and ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
concatenation - Java concat with integer and string - Stack Overflow
Do you need to concatenate the int and the string, or do you need to print the string n times, n being the int? ... Do you know beforehand if the concatenated string would have the message first or the int first? Meaning would the string be "Bye2" or "2Bye"? ... Save this answer. Show activity on this post. You can concatenate String with int in Java ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 6, 2016
java - How to concatenate int and string - Stack Overflow
You also have the option to parse your data (this may be useful to you if you ever want to get the int's back from your array. ... Sign up to request clarification or add additional context in comments. ... The question is not about C#, and OP is not asking about concatenating strings. More on stackoverflow.com
๐ŸŒ stackoverflow.com
concatenating string and numbers Java - Stack Overflow
You get the result of the ... then the concatenation of a String and an int due to the +. ... You need the parentheses to express the precedence you wish for. ... I know ! But that is not my question . 2012-08-19T18:15:43.697Z+00:00 ... It requires nothing more than actually reading the Java operator ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
JA-VA Code
java-performance.info โ€บ home โ€บ exploring various methods for adding int to string in java
Adding Int To String Java: Adding Integers Made Easy
September 25, 2023 - The + operator is the most straightforward way to combine integers and strings in Java. When you use + between a string and an integer, Java automatically converts the integer to its string representation and concatenates it with the existing string.
๐ŸŒ
Quora
quora.com โ€บ Does-Java-allow-strings-and-integers-to-be-concatenated
Does Java allow strings and integers to be concatenated? - Quora
There is no way to concatenate an integer primitive or the wrapper this way without making a string out of the integer. ... We ranked the top 10 wealth management firms in the US. Firms were evaluated using objective data including AUM, clients per advisor and fee structures. ... Two people have suggested that it's something to do with what println does or expects but this is wrong. "foo"+10 is an expression in Java ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java-program-to-concatenate-a-string-and-integers
Java Program to concatenate a String and Integers
To concatenate a String and some integer values, you need to use the + operator. Letโ€™s say the following is the string. String str = "Demo Text"; Now, we will concatenate integer values.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-concatenate-two-integer-values-into-one
How to concatenate two Integer values into one? - GeeksforGeeks
// C program to concatenate // two integers into one #include <stdio.h> #include <string.h> #include <stdlib.h> // Function to concatenate // two integers into one int concat(int a, int b) { char s1[20]; char s2[20]; // Convert both the integers ...
Published ย  July 11, 2025
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 35821519 โ€บ java-concat-with-integer-and-string
concatenation - Java concat with integer and string - Stack Overflow
March 6, 2016 - Since java 7, appending string using + internally uses StringBuilder. It makes the code more readable if you just use + to appends instead of initializing a StringBuilder and calling append on the object.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 2887064 โ€บ in-java-how-can-we-concatenate-integers-using-an-object-of-type-string
In Java, how can we concatenate integers using an object ...
September 21, 2021 - sl_scroll_/de/Discuss/2848516/how-is-python-used-in-the-ai-artificial-intelligence-fieldPending ยท Maximum Storage Duration: SessionType: HTML Local Storage ยท sl_scroll_/de/Discuss/2864826/java-erp-softwarePending
๐ŸŒ
Java67
java67.com โ€บ 2015 โ€บ 05 โ€บ 4-ways-to-concatenate-strings-in-java.html
4 ways to concatenate Strings in Java [Example and Performance] | Java67
Just remember that, when you have two or more primitive type values e.g. char, short, or int, at the beginning of your string concatenation, you need to explicitly convert the first of them to a String.
๐ŸŒ
javathinking
javathinking.com โ€บ blog โ€บ java-convert-int-to-string-and-concatenate
Java: Convert Int to String and Concatenate โ€” javathinking.com
On the other hand, String is a class that represents a sequence of characters. Since int is a primitive type and String is an object, they cannot be directly combined. Therefore, we need to convert the int to a String before concatenation.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_strings_numbers.asp
Java Numbers and Strings
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 ... Java uses the + operator for both addition and concatenation.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2015 โ€บ 01 โ€บ 3-examples-to-concatenate-string-in-java.html
3 Examples to Concatenate String in Java
You can use this operator even ... String "123". The other two ways to concatenate String in Java is by using StringBuffer and StringBuilder....
Top answer
1 of 5
11

The first will become:

StringBuilder sb = new StringBuilder (String.valueOf (someStr));
sb.append (3);
sb.append ("]");
String newStr = sb.toString ();

the second will become:

StringBuilder sb = new StringBuilder (String.valueOf (someStr));
sb.append ("3");
sb.append ("]");
String newStr = sb.toString ();

Here is disassembly:

public String foo (String someStr)
{
    String newStr = someStr + 3 + "]";
    return newStr;
}

public String bar (String someStr)
{
    String newStr = someStr + "3" + "]";
    return newStr;
}

public java.lang.String foo(java.lang.String);
Code:
   0: new           #16                 // class java/lang/StringBuilder
   3: dup
   4: aload_1
   5: invokestatic  #18                 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
   8: invokespecial #24                 // Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
  11: iconst_3
  12: invokevirtual #27                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
  15: ldc           #31                 // String ]
  17: invokevirtual #33                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  20: invokevirtual #36                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
  23: astore_2
  24: aload_2
  25: areturn

public java.lang.String bar(java.lang.String);
Code:
   0: new           #16                 // class java/lang/StringBuilder
   3: dup
   4: aload_1
   5: invokestatic  #18                 // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
   8: invokespecial #24                 // Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
  11: ldc           #44                 // String 3
  13: invokevirtual #33                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  16: ldc           #31                 // String ]
  18: invokevirtual #33                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  21: invokevirtual #36                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
  24: astore_2
  25: aload_2
  26: areturn
2 of 5
7

There won't be any noticeable difference between both. Use what you find the most logical and readable. I would use

String newStr = someStr + "3]";
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ getting-started-with-java โ€บ lessons โ€บ java-string-magic-understanding-concatenation-operations
Java String Magic: Understanding Concatenation Operations
What's truly remarkable here is that Java implicitly converts the integer apples to a string before performing the concatenation. Pretty useful, isn't it? ... Java's String class provides another string concatenation tool โ€” the concat method. Let's examine how we use it to join "Hello, " and "World!":
๐ŸŒ
ThoughtCo
thoughtco.com โ€บ concatenation-2034055
Understanding the Concatenation of Strings in Java
May 18, 2025 - Using the + operator is the most common way to concatenate two strings in Java. You can provide either a variable, a number, or a String literal (which is always surrounded by double quotes).
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ concatenate two ints without string
r/javahelp on Reddit: Concatenate two ints without String
November 3, 2015 -

Hello there

Is there a way to do this without converting to String?

int x = 5;
int y = 1;
int z = x + y; // I want the result to be 51, not 6 

I know I could just do

String z = "" + x + y;

But that seems like a messy workaround and it also needs to be converted back to an int if I ever want to work with it again.

But then and again, I could write a method for that but in all the years Java has existed someone else must have ran into this issue, right?

๐ŸŒ
OpenMRS
talk.openmrs.org โ€บ development
Sanjeev Mansotra - How to add the two or more numbers in to string in java? - Development - OpenMRS Talk
January 9, 2024 - Hi all, my name is Sanjeev Mansotra. I am unable to find an option to add two or more numbers into to string in Java, can anyone help me in this situation?