I have an int and I want to convert it to a string. Should be simple, right? But the compiler complains it can't find the symbol when I do:
int tmpInt = 10; String tmpStr10 = String.valueOf(tmpInt);
What is wrong with the above? And, how do I convert an int (or long) to a String?
Edit: valueOf not valueof ;)
We can convert int value to Double object by instantiating Double class or calling Double. valueOf() method. Let's see the simple code to convert int to Double in java.
Use this String.valueOf(value);
Normal ways would be Integer.toString(i)
or String.valueOf(i)
.
int i = 5; String strI = String.valueOf(i);
Or
int aInt = 1; String aString = Integer.toString(aInt);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With