Android how to convert int to String?

Android

Android Problem Overview


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 ;)

Android Solutions


Solution 1 - Android

Use this String.valueOf(value);

Solution 2 - Android

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);

Solution 3 - Android

You called an incorrect method of String class, try:

int tmpInt = 10;
String tmpStr10 = String.valueOf(tmpInt);

You can also do:

int tmpInt = 10;
String tmpStr10 = Integer.toString(tmpInt);

Solution 4 - Android

Use Integer.toString(tmpInt) instead.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJB_UserView Question on Stackoverflow
Solution 1 - AndroidURAndroidView Answer on Stackoverflow
Solution 2 - AndroidK_AnasView Answer on Stackoverflow
Solution 3 - AndroidBamsBamxView Answer on Stackoverflow
Solution 4 - AndroidKarakuriView Answer on Stackoverflow