HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

Java - Convert integer to string

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
stringconvertintegerjava

Problem

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)

Context

Stack Overflow Q#5071040, score: 1099

Revisions (0)

No revisions yet.