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); } }
Discussions

Java convert an Int to a String | Go4Expert
Discussion in 'Java' started by tombezlar, Mar 24, 2021. More on go4expert.com
🌐 go4expert.com
March 24, 2021
java - How do I convert from int to String? - Stack Overflow
I'm working on a project where all conversions from int to String are done like this: int i = 5; String strI = "" + i; I'm not familiar with Java. Is this usual practice or is something wrong, a... More on stackoverflow.com
🌐 stackoverflow.com
Converting a Number to a String
The docs will answer that question quite clearly https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#toString(int) https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#valueOf(int) under the String.valueOf(int) description: The representation is exactly the one returned by the Integer.toString method of one argument. to make it even more clear if we look at the source code for String.valueOf(int) https://hg.openjdk.java.net/jdk7u/jdk7u6/jdk/file/8c2c5d63a17e/src/share/classes/java/lang/String.java we find that it literally just calls Integer.toString(int) public static String valueOf(int i) { return Integer.toString(i); } More on reddit.com
🌐 r/javahelp
3
6
August 14, 2022
how to convert int to string
Joel Velez is having issues with: I don't know why it is giving me compile errors. ... More on teamtreehouse.com
🌐 teamtreehouse.com
2
April 13, 2015
People also ask

Q1. Why do we need to convert a string to an int in Java?
We often need to convert a string to an int while working with user inputs, reading data from files, or APIs where numerical data is stored in text format.
🌐
intellipaat.com
intellipaat.com › home › blog › string to integer java
How to Convert String to Integer in Java?
Q3. How to convert a string to an integer without using any direct method in Java?
To convert a string to an integer without using any direct method, iterate through each character, subtract ‘0’ to get the numeric value, and build the number using multiplication and addition.
🌐
intellipaat.com
intellipaat.com › home › blog › string to integer java
How to Convert String to Integer in Java?
Q2. What is the difference between Integer.valueOf() and Integer.parseInt()?
The major difference between Integer.valueOf() and Integer.parseInt() is that valueOf() returns an Integer object (wrapper class), while parseInt() returns a primitive int.
🌐
intellipaat.com
intellipaat.com › home › blog › string to integer java
How to Convert String to Integer in Java?
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-convert-string-to-int-in-java
String to int in Java - GeeksforGeeks
The Integer.valueOf() method converts a String to an Integer object instead of a primitive int. We can unbox it to an int. Note: valueOf() method uses parseInt() internally to convert to integer.
Published   July 23, 2025
🌐
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 - Just add + to empty string and int or any number will be converted to String. Shortcut method but does the job for sure. For simple cases - yes, it works: If you're just looking for quick things like logging a value or debugging, the "" + number ...
🌐
Go4Expert
go4expert.com › forums › java-convert-int-string-t35421
Java convert an Int to a String | Go4Expert
March 24, 2021 - 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...
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › java › how do i convert a string to an int in java?
How do I convert a String to an int in Java? | Sentry
How can I convert a String to an int in Java? The two easiest ways to convert a string to an integer in Java are to use Integer.parseInt() or Integer.valueOf(). Here is an example of each.
🌐
Oracle
docs.oracle.com › en › java › javase › 20 › docs › api › java.base › java › lang › Integer.html
Integer (Java SE 20 & JDK 20)
July 10, 2023 - The string value of this property is then interpreted as an integer value, as per the decode method, and an Integer object representing this value is returned; in summary: If the property value begins with the two ASCII characters 0x or the ASCII character #, not followed by a minus sign, then the rest of it is parsed as a hexadecimal integer exactly as by the method valueOf(java.lang.String, int) with radix 16.
🌐
Codemia
codemia.io › knowledge-hub › path › java_-_convert_integer_to_string
Java - Convert integer to string
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Study.com
study.com › business courses › business 104: information systems and computer applications
How to Convert Int to String in Java - ValueOf Method | Study.com
This is because a String can contain both numeric and text values. To unlock this lesson you must be a Study.com member Create an account · We will use the valueOf method in Java to convert an int to a String.
🌐
Udemy
blog.udemy.com › home › how to convert integers to strings in java
How to Convert Integers to Strings in Java - Udemy Blog
December 4, 2019 - int abc=10; double bcd=12.23; //String declaration String abc=“”Hello”; StringBuffer str1=new StringBuffer(”Hello World”); Numeric values are used for performing calculation and manipulations. Every data type in Java has a size limit and value range. Want to know about core Java concepts?
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);
🌐
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!

🌐
Educative
educative.io › answers › how-to-convert-an-integer-to-a-string-in-java
How to convert an integer to a string in Java
The first argument is any string containing %d. The second argument is the integer you want to convert. This method will replace %d with your integer.
🌐
Java67
java67.com › 2015 › 08 › 2-ways-to-parse-string-to-int-in-java.html
2 ways to parse String to int in Java - Example Tutorial | Java67
So every time you pass a numeric String which is in the range of -128 to 127, Integer.valueOf() doesn't create a new Integer object but returns the same value from the cached pool. The only drawback is that Integer.valueOf() returns an Integer object and not an int primitive value like the parseInt() method, but given auto-boxing is available in Java from JDK 5 onward, which automatically convert an Integer object to an int value in Java.
🌐
Baeldung
baeldung.com › home › java › java array › converting a string array into an int array in java
Converting a String Array Into an int Array in Java | Baeldung
January 8, 2024 - In this article, we’ve learned two ways to convert a string array to an integer array through examples. Moreover, we’ve discussed handling the conversion when the string array contains invalid number formats. If our Java version is 8 or later, the Stream API would be the most straightforward ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Integer.html
Integer (Java Platform SE 8 )
October 20, 2025 - The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value or an ASCII plus sign '+' ('\u002B') to indicate a positive value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.
🌐
Team Treehouse
teamtreehouse.com › community › how-to-convert-int-to-string
how to convert int to string (Example) | Treehouse Community
April 13, 2015 - Use the class Integer.toString function. This will parse the integer and return a static string. https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html · 5,969 Points · Ivan Sued · 5,969 Points April 13, 2015 9:09pm · I think the ...
🌐
Intellipaat
intellipaat.com › home › blog › string to integer java
How to Convert String to Integer in Java?
July 22, 2025 - In this guide, you will learn how and when to use different methods to convert a string to int in Java with examples, and also know how to fix errors if the string is not valid.