Android, how to convert int to String?

I have an int and I want to convert it to a string. It should be simple, right? But the compiler complains that it cannot find the character when I do:

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

What is wrong with that? And how do I convert int (or long) to String?

+53
android
Apr 05 '13 at 14:40
source share
4 answers

Use String.valueOf(value);

+155
Apr 05 '13 at
source share

Common methods can 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); 
+25
Apr 05
source share

You called the wrong method of the String class, try:

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

You can also do:

 int tmpInt = 10; String tmpStr10 = Integer.toString(tmpInt); 
+13
Apr 05 '13 at
source share

Use Integer.toString(tmpInt) instead.

+6
Apr 05
source share



All Articles