There are multiple ways:

  • String.valueOf(number) (my preference)
  • "" + number (I don't know how the compiler handles it, perhaps it is as efficient as the above)
  • Integer.toString(number)
Answer from Bozho on Stack Overflow
🌐
Educative
educative.io › answers › how-to-convert-an-integer-to-a-string-in-java
How to convert an integer to a string in Java
System.out.println("After conversion (using Static method): " + Integer.toString(x).getClass().getName()); ... These two classes build a string by the append() method.
🌐
GeeksforGeeks
geeksforgeeks.org › java › different-ways-for-integer-to-string-conversions-in-java
Java Convert int to String | How to Convert an Integer into a String - GeeksforGeeks
April 9, 2025 - Example 2: Converting int(base 8 or octal number) to String using Integer class method toOctalString(). ... // Java Program to Illustrate Integer to String Conversions // Using Special Radix In Octal Numbers // Main class class Geeks { // Main ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
October 20, 2025 - The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.
Top answer
1 of 16
983

Normal ways would be Integer.toString(i) or String.valueOf(i).

The concatenation will work, but it is unconventional and could be a bad smell as it suggests the author doesn't know about the two methods above (what else might they not know?).

Java has special support for the + operator when used with strings (see the documentation) which translates the code you posted into:

StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(i);
String strI = sb.toString();

at compile-time. It's slightly less efficient (sb.append() ends up calling Integer.getChars(), which is what Integer.toString() would've done anyway), but it works.

To answer Grodriguez's comment: ** No, the compiler doesn't optimise out the empty string in this case - look:

simon@lucifer:~$ cat TestClass.java
public class TestClass {
  public static void main(String[] args) {
    int i = 5;
    String strI = "" + i;
  }
}
simon@lucifer:~$ javac TestClass.java && javap -c TestClass
Compiled from "TestClass.java"
public class TestClass extends java.lang.Object{
public TestClass();
  Code:
   0:    aload_0
   1:    invokespecial    #1; //Method java/lang/Object."<init>":()V
   4:    return

public static void main(java.lang.String[]);
  Code:
   0:    iconst_5
   1:    istore_1

Initialise the StringBuilder:

   2:    new    #2; //class java/lang/StringBuilder
   5:    dup
   6:    invokespecial    #3; //Method java/lang/StringBuilder."<init>":()V

Append the empty string:

   9:    ldc    #4; //String
   11:    invokevirtual    #5; //Method java/lang/StringBuilder.append:
(Ljava/lang/String;)Ljava/lang/StringBuilder;

Append the integer:

   14:    iload_1
   15:    invokevirtual    #6; //Method java/lang/StringBuilder.append:
(I)Ljava/lang/StringBuilder;

Extract the final string:

   18:    invokevirtual    #7; //Method java/lang/StringBuilder.toString:
()Ljava/lang/String;
   21:    astore_2
   22:    return
}

There's a proposal and ongoing work to change this behaviour, targetted for JDK 9.

2 of 16
258

It's acceptable, but I've never written anything like that. I'd prefer this:

String strI = Integer.toString(i);
🌐
Software Testing Help
softwaretestinghelp.com › home › java › 8 methods to convert an integer to string in java
8 Methods To Convert An Integer To String In Java
April 1, 2025 - Let’s see the Java convert int to String way using the StringBuffer methods. ... public StringBuffer append(int i) This method appends the string representation of the int argument to the sequence. Parameters: i: This is an integer.
🌐
GeeksforGeeks
geeksforgeeks.org › java › integer-tostring-in-java
Integer toString() in Java - GeeksforGeeks
July 5, 2018 - Parameters: "a" the integer value to be converted, "base" the radix/base used for conversion. Return Value: Returns a string representation of the integer in the specified base.
🌐
Sentry
sentry.io › sentry answers › java › how do i convert an integer to a string in java?
How Do I Convert an Integer to a String in Java? | Sentry
The String.valueOf() method is one of the simplest ways to convert an Integer to a String: ... class Main { public static void main(String[] args) { int number = 123; String numberString = String.valueOf(number); System.out.println("Converted ...
Find elsewhere
🌐
Reddit
reddit.com › r/javahelp › converting a number to a string
r/javahelp on Reddit: Converting a Number to a String
August 14, 2022 -

Hey, all. I was working on some Codewars fundamentals and I came across this problem. My solution was accepted and, on the list of acceptable solutions, I see what seems to be an equally useful solution. I just wondered if there's any reason to use one over the other in any particular situation or if they do the same thing all the time. The passed in variable was some integer num.

My solution was:

return Integer.toString(num);

The other solution I saw was:

return String.valueOf(num);

Any insight would be much appreciated. Thanks!

🌐
FavTutor
favtutor.com › blogs › int-to-string-java
Convert Int to String in Java using 08 Methods (with code)
December 28, 2022 - Here, in this example, we are using the toBinaryString() method to achieve the same conversion from an integer to a String as shown. ... int a = 1567; int b = -1567; // Concatenating with empty strings String str1 = "" + a; String str2 = "" ...
🌐
IONOS
ionos.com › digital guide › websites › web development › java int to string
How to convert an int to a string in Java - IONOS
December 18, 2024 - If you want to convert an int into a string, you have five options. We’ll introduce each of them to you below. The options are: The method Integer(int).toString from the integer class
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › converting.html
Converting Between Numbers and Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
Each of the Number subclasses includes a class method, toString(), that will convert its primitive type to a string. For example: int i; double d; String s3 = Integer.toString(i); String s4 = Double.toString(d);
🌐
HappyCoders.eu
happycoders.eu › java › how-to-convert-int-to-string-fastest
How to Convert int to String in Java – The Fastest Way
December 2, 2024 - Extensive benchmark tests have shown that across all Java versions, "" + i is the fastest way to convert an integer to a String. While the margin for Java 7 and Java 8 was still an impressive 15%, it has dropped to about 2% since Java 9, so ...
🌐
Baeldung
baeldung.com › home › java › java string › integer.tostring() vs string.valueof() in java
Integer.toString() vs String.valueOf() in Java | Baeldung
April 7, 2025 - Interestingly, the returned String representation is exactly the same as the one returned by the Integer.toString(int i) method. It is because internally, it uses Integer.toString() method. Let’s look at its internal implementation as given ...
🌐
Vultr Docs
docs.vultr.com › java › examples › convert-int-type-variables-to-string
Java Program to convert int type variables to String | Vultr Docs
November 25, 2024 - Define an integer value. Concatenate it with an empty string to get a string result. ... By concatenating number with an empty string, Java automatically converts the integer to a string.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › Integer.html
Integer (Java SE 21 & JDK 21)
January 20, 2026 - The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading 0s.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-string-to-integer-and-integer-to-string-in-java
How to convert String to Integer and Integer to String in Java?
Java lang package provides Integer class which has methods to convert integer to String and vice versa. You can convert a String to an integer using the parseInt() method and Integer to String using the toString()&nbs
🌐
Java67
java67.com › 2012 › 10 › best-way-to-convert-numbers-to-string-in-java-example.html
Best way to Convert Integer to String in Java with Example | Java67
java 8 · coding · sql · books · oop · interview · certification · free resources · best · Integer to String conversion in Java · There are many ways to convert an Integer to String in Java e.g.
🌐
Baeldung
baeldung.com › home › java › java list › convert a list of integers to a list of strings
Convert a List of Integers to a List of Strings - Java
June 9, 2025 - Now, our goal is to convert each integer element in INTEGER_LIST to a String, for example, 1 to “1”, 2 to “2”, and so on. Finally, the result should be equal to: List<String> EXPECTED_LIST = Arrays.asList("1", "2", "3", "4", "5", "6", "7"); In this tutorial, we’ll address three different ways to do that: ... Next, let’s see them in action. Java Stream API is available on Java 8 and later versions.
🌐
CodeGym
codegym.cc › java blog › strings in java › how to convert int to string in java
Convert int to String in Java
December 18, 2024 - Just add to int or Integer an empty string "" and you’ll get your int as a String. It happens because adding int and String gives you a new String. That means if you have int x = 5, just define x + "" and you’ll get your new String.