Convert int to String in Java

Sometimes, we may need to Convert int to String in Java. An int can be converted to String in java in following ways.

1) Using String.valueOf(int i):

The String.valueOf() method takes integer value as an input and returns the String representation of the int argument.

Syntax:

Parameters:
i – an int.

Returns:
a string representation of the int argument.

2) Using Integer.toString(int i):

This method is same as String.valueOf(int i) method and returns a String object representing this Integer’s value.

Syntax:

Parameters:
i – an integer to be converted.

Returns:
Returns a String object representing the specified integer. The argument is converted to signed decimal representation and returned as a string.

Example:

Let’s see how to Convert int to String with an example. Here we have taken 2 integer variables which are to be converted to String.

Let’s see the output of the above program.

Output:

The above program demonstrates the int to String conversion with an example. If you want to convert String to int in Java, then read tutorial on Convert String to int in Java.