Write Java program to Convert an Integer to String


This is a Java program that demonstrates how to convert an integer value to a string using the Integer.toString() method. In this program, an integer variable a is initialized with the value of 26. Then, a null string variable str is declared.

The program then uses the System.out.println() method to print the value of the integer variable a. Next, the Integer.toString() method is called, passing in the integer variable a as an argument. This method returns a string representation of the integer value. The returned string is then assigned to the str variable.

Finally, the program uses the System.out.println() method to print the string representation of the integer value that was stored in the str variable.

Source Code

public class IntegerToString
{
	public static void main(String args[])
	{
		int a = 26;
		String str = null;
		System.out.println("Integer Values : " + a);
 
		//convert integer to string
		str = Integer.toString(a);
		System.out.println("Integer to string : " + str);
	}
}

Output

Integer Values : 26
Integer to string : 26