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
๐ŸŒ
Browserling
browserling.com โ€บ tools โ€บ decimal-to-text
Decimal to Text Converter - Convert Decimal to String - Online - Browserling Web Developer Tools
Useful, free online tool that converts decimal integer values to plain text. No ads, nonsense, or garbage, just a dec to text converter. Press a button โ€“ get the result.
๐ŸŒ
Online String Tools
onlinestringtools.com โ€บ convert-decimal-to-string
Convert Decimal to a String โ€“ Online String Tools
Free online decimal to string converter. Just load your decimal and it will automatically get converted to a string. There are no intrusive ads, popups or nonsense, just a decimal to string converter. Load a decimal, get a string.
๐ŸŒ
Text Compare
textcompare.io โ€บ string-to-int-converter
String to INT Converter Online
String to Integer (INT) Converter is a tool that simplifies the conversion of textual data (strings) into integer values. In computer programming, strings are sequences of characters (text), and integers are numerical data types.
๐ŸŒ
Convert String
convertstring.com
Convert String - Online String Conversion tools
Convert String offers resources for converting strings between formats. If you need a fast free online tool for applying common string functions or string manipulation routines then you are in the right place!
๐ŸŒ
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 - Using concatenation with an empty string. The Integer class has a static method toString() that returns a String object representing the specified int parameter. The argument is converted and returned as a string instance.
๐ŸŒ
PhraseFix
phrasefix.com โ€บ tools โ€บ decimal-to-string
Decimal to String Converter - PhraseFix
Free online tool that converts decimal to string. Simply enter the decimal and the online tool will convert it into text.
๐ŸŒ
Browserling
browserling.com โ€บ tools โ€บ text-to-decimal
Text to Decimal Converter - Convert Text to Decimal String - Online - Browserling Web Developer Tools
For example, if you're writing a web application that transfers messages using a simple non-binary text protocol, then it may get tricky to transfer multi-byte characters (such as Unicode symbols and emojis). With this utility, you can convert any text, Unicode glyphs, and multi-byte strings into ...
Find elsewhere
๐ŸŒ
Kjur
kjur.github.io โ€บ jsrsasign โ€บ sample โ€บ tool_intary.html
jsrsasign: Integer array converter
This tool converts from a string of integer array (ex. ' [ 123, 34, 101, ... ] ') to a hexadecimal string or raw string.
๐ŸŒ
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 - The easiest way to convert int to String is very simple. 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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ how-to-convert-an-integer-to-a-string-in-c
How to Convert an Integer to a String in C? - GeeksforGeeks
July 23, 2025 - We can convert an integer to a string manually by extracting each digit one by one and converting it to its corresponding character by using their ASCII code and storing it in the character array to form a string.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-an-integer-to-a-string-in-java
How to convert an integer to a string in Java
It returns a string. You can use it as a static function of the Integer class like this: ... Or, use the normal version of the Integer classโ€™ object. This cannot be used with the primitive type int, so remember to convert it to an Integer first by passing it to the constructor or simple assignment using โ€˜=โ€™ operator (see the example below) :
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ int-to-string
How to Convert Int to String in C? 3 Ways With Code
October 23, 2025 - Learn three simple ways to convert an int to a string in C using sprintf(), itoa(), and other methods. Includes code examples!
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
Convert int to string and print in serial monitor - Programming - Arduino Forum
April 11, 2024 - So I am receiving data over bluetooth which is in the form of ascii characters. So 255 comes in as 50,53,53 So what I need to do is convert the intergers into strings then concatenate the strings together then convert the new string back into a int. So myRecievednumbers is an array and in the ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-integer-to-string-in-python
Convert integer to string in Python - GeeksforGeeks
This is similar to f-strings but works with older versions of Python (before 3.6). ... The %s keyword allows us to insert an integer (or any other data type) into a string.
Published ย  July 12, 2025
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);
๐ŸŒ
DenCode
dencode.com โ€บ string
String Encoder / Decoder, Converter Online - DenCode
String encoding and decoding converter. e.g. HTML Escape / URL Encoding / Quoted-printable / and many other formats!
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ how are integers actually converted into their string representations under the hood?
r/C_Programming on Reddit: How are integers actually converted into their string representations under the hood?
July 17, 2022 -

I am aware that the C standard provides plenty of functions for converting binary values into human-readable strings, but I am interested in learning how they actually accomplish this, particularly with integers.

Letโ€™s say that as an educational exercise I am trying to convert integer values to strings without the help of LibC.

There are two (naive) approaches that come to my mind:

  1. Manually create a giant lookup table containing the string representation for every possible value of the desired type.

  2. Convert the numbers in the same way a human would, going bit by and adding together the corresponding powers of 2 as needed. If you create a function that adds numbers by manipulating their string representations directly, then you would only need a lookup table that contains the strings for the necessary powers of 2.

The second option is actually what I used a while back on a very basic big number library.

However, both of these options seem incredibly inefficient.

While every compiler/implementation will be a little different, is there some kind of common algorithm that is used to do this efficiently?

(Google has been unhelpful, either telling me to use the standard functions, or showing me the algorithm to turn binary strings into actual ints)

Edit: For simplicity, assume that a โ€œstringโ€ is a typical ASCII, null-terminated char array/pointer.

Edit 2: Typos

Edit 3: Thank you for the helpful comments :)

Top answer
1 of 7
27
You can just mod by 10 to get the value of the first digit and then convert that to an ASCII character by adding '0' to it, then divide the input by ten and repeat until the remaining value is 0. You then concatenate the individual characters into a string.
2 of 7
4
You don't need to worry about bits at all - the CPU does this automatically. Here's a simple algorithm that's somewhat dumb and can't handle negative numbers, but I think it gets the point across. Chop off the last digit of your number: d1 = n % 10. Save the remaining digits: n1 = n / 10. There are only 10 possible cases: 0, 1, ..., 9. Each of them maps to the corresponding character: '0', '1', ..., '9'. You could store them in a string: char *digits = "0123456789"; Append the character digits[d1] to your string. If the remaining number n1 isn't zero, chop off its last digit again: d2 = n1 % 10. Save the remaining digits: n2 = n1 / 10. Again, you have 10 possible choices. Append the corresponding character digits[d2] to the string. Continue until the number becomes zero. Return the reversed string. Note how you don't need to worry about bits here. You just say n % 10 - and the compiler emits instructions that the CPU later executes by messing around with bits accordingly to produce the remainder of an integer. How it does it isn't terribly important to the programmer. Same for division. However, some instruction set architectures (like the most basic versions of RISC-V) don't have an "integer divide" instruction, so it can indeed be implemented in code using bit wrangling magic.