r/learnjava • • May 13 '16

Convert an int to a String in java

http://programtalk.com/java/convert-int-to-string-in-java
0 Upvotes

1 comment sorted by

4

u/OA998 May 13 '16 edited May 13 '16

Use the Integer class. No imports necessary.

int x = 12;
String s = Integer.toString(x);
System.out.println(x+10);
System.out.println(s+10);

Output: 
    22
    1210

Likewise, you can use the String class:

int x = 12;
String s = String.valueOf(x);