snippetjavaCritical
Java - Convert integer to string
Viewed 0 times
stringconvertintegerjava
Problem
Given a number:
Which would be the "best" way to convert this to a string:
I have tried searching (googling) for an answer but no many seemed "trustworthy".
int number = 1234;Which would be the "best" way to convert this to a string:
String stringNumber = "1234";I have tried searching (googling) for an answer but no many seemed "trustworthy".
Solution
There are multiple ways:
String.valueOf(number)(my preference)
"" + number(I don't know how the compiler handles it, perhaps it is as efficient as the above)
Integer.toString(number)
Context
Stack Overflow Q#5071040, score: 1099
Revisions (0)
No revisions yet.