18 Aug Java Program to convert integer to string
The toString() method is used to convert integer to string in Java. The syntax is as follows:
1 2 3 |
public static String toString(int val) |
Here, val is the integer to be converted.
Example 1
Following is an example to convert integer to string in Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class Example { public static void main( String args[] ) { int p = 7; System.out.println("Integer Value = "+p); System.out.println("String Value = "+(Integer.toString(p))); } } |
Output
1 2 3 4 |
Integer Value = 7 String Value = 7 |
Example 2
1 2 3 4 5 6 7 8 9 10 11 |
public class Example { public static void main( String args[] ) { Integer p = new Integer(10); System.out.println("String = "+p.toString()); } } |
Output
1 2 3 |
String = 10 |
No Comments