Java – Convert integer to string

Total
0
Shares

Given a number:

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)

Source: StackOverflow.com

Leave a Reply

Your email address will not be published. Required fields are marked *