I want to convert a primitive to a string, and I tried:
myInt.toString();
This fails with the error:
int cannot be derefere
One other way to do it is to use:
String.valueOf(myInt);
This method is overloaded for every primitive type and Object
. This way you don't even have to think about the type you're using. Implementations of the method will call the appropriate method of the given type for you, e.g. Integer.toString(myInt)
.
See http://java.sun.com/javase/6/docs/api/java/lang/String.html.