Convert an Integer into a String

In this section, you will learn to convert an integer
type data into a string type. The java.lang package provides this
conversion functionality through toString() method.
Code Description:
This program takes an integer number at the console and it
converts it into a string format using the Integer(str).toString() method.
The given number takes an integer number that must be converted into an string
format.
The toString() method convert Integer number to string number.
toString():
The toString() method converts an integer value into a String.
Here is the code of this program:
import java.io.*;
import java.lang.*;
public class IntegerToString {
public static void main(String[] args) throws IOException{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the integer value!");
String str = read.readLine();
String s = new Integer(str).toString();
System.out.println("String:=" +s);
}
}
|
Download this program:
Output this program.
C:\corejava>java IntegerToString
Enter the integer value!
24
string: 24
C:\corejava> |

|