Java Int to String Syntax
valueOf() is a static method of the String class, and toString() is a static method of the Integer class. For an int, String.valueOf() returns exactly what Integer.toString() returns.
Java Int to String Examples
The following are examples of converting an int to a string in Java. You can run any of these examples in the online Java code runner and try them with your own numbers.
Convert an int to String with String.valueOf()
valueOf() returns the digits of the number as a new String. String methods such as length() then work on the result.
Convert an int to String with Integer.toString()
Integer.toString() takes an optional radix. Pass 2 for a binary string or 16 for a hexadecimal one.
Convert an int to String with concatenation
The + operator turns a number into a string when the other operand is a string. Java evaluates + from left to right, so numbers added before the first string are summed as numbers.
Convert an int to String with leading zeros
String.format() with the %0Nd format pads the number with zeros to N digits. A number that already has N digits or more is not cut.