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
🌐
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 - Note: This method is not efficient as an instance of the Integer class is created before conversion is performed. And deprecated and marked as removal. Here, we will declare an empty string and using the '+' operator, we will simply store the resultant as a string. Now by this, we are successfully able to append and concatenate these strings. ... // Java Program to Illustrate Integer to String Conversions // Using Concatenation with Empty String class Geeks { // Main driver method public static void main(String args[]) { // Custom integer values int a = 1234; int b = -1234; // Concatenating with empty strings String str1 = "" + a; String str2 = "" + b; // Printing the concatenated strings System.out.println("String str1 = " + str1); System.out.println("String str2 = " + str2); } }
🌐
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.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-convert-integer-to-string-in-java
Int to String in Java – How to Convert an Integer into a String
January 5, 2023 - You can convert variables from one data type to another in Java using different methods. In this article, you'll learn how to convert integers to strings in Java in the following ways: Using the Integer.toString() method. Using the String.valueOf(...
🌐
iO Flood
ioflood.com › blog › int-to-string-java
Int to String Java Conversion: Methods and Examples
February 26, 2024 - In this guide, we’ll walk you through the process of converting integers to strings in Java, from the basics to more advanced techniques.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › 4 useful methods to convert java int to string with examples
4 Useful Methods to Convert Java Int to String with Examples
July 28, 2025 - Learn Java the right way! Our course teaches you essential programming skills, from coding basics to complex projects, setting you up for success in the tech industry. ... This method is the most straightforward, easy and commonly recommended method when you need to convert an int to a String. String.valueOf() is a static method in the String class and is designed for this purpose. This method takes an integer and returns its string form.
🌐
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 do an int to string conversion in Java with an empty string, you’ll need the operator +. You can use + to add the integer to an empty string and set the result as a string.
🌐
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
In this example, String.valueOf(number) converts the int value, number, to a String. Alternatively, you can use the Integer.toString() method to convert an Integer to a String:
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int. In addition, this class provides several methods for converting an int to a String and a String to an int, as well ...
🌐
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.
🌐
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);
🌐
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!

🌐
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.
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:

CopyStringBuilder 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:

Copysimon@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:

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

Append the empty string:

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

Append the integer:

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

Extract the final string:

Copy   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:

CopyString strI = Integer.toString(i);
🌐
Programiz
programiz.com › java-programming › examples › int-to-string-conversion
Java Program to convert int type variables to String
Build the coding confidence you need to become a developer companies will fight for · Stop copy pasting code you don't actually understand ... Become a certified Java programmer. ENROLL ... Created with over a decade of experience. ... Created with over a decade of experience and thousands of feedback. ... Try Programiz PRO! ... Become a certified Java programmer. Try Programiz PRO! ... class Main { public static void main(String[] args) { // create int variable int num1 = 36; int num2 = 99; // convert int to string // using valueOf() String str1 = String.valueOf(num1); String str2 = String.valueOf(num2); // print string variables System.out.println(str1); // 36 System.out.println(str2); // 99 } }
🌐
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.
🌐
Go4Expert
go4expert.com › forums › java-convert-int-string-t35421
Java convert an Int to a String | Go4Expert
Here are 3 ways to convert an int to a String String s = String.valueOf(n); String s = Integer.toString(n); String s = "" + n; I understand what we...
🌐
Edureka
edureka.co › blog › convert-int-to-string-in-java
How to Convert Int to String in Java? String Conversion Example | Edureka
November 29, 2022 - The returned value for both expressions is a Java String that represents the integer “i” argument. If the radix parameter is used, the returned string is specified by the respective radix. Convert Integer to String using Integer.toString().
🌐
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.