Converting primitives to strings

Edit on Github instead

Java's static toString(int) and toString(double) methods turn an int, double, or boolean into a String.

int i = 104;
String s = Integer.toString(i);
// s now has the value "104"

double d = 994.4;
String t = Double.toString(d);
// t now has the value "994.4"

More generally, it looks like:

String <stringName> = <WrapperClassName>.toString(<primative>);

Suggest changes

Related links

URL Topic Source