Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to convert int to String? [duplicate]

Tags:

android

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

like image 349
JB_User Avatar asked Apr 05 '13 14:04

JB_User


People also ask

Can int be casted to double?

We can convert int value to Double object by instantiating Double class or calling Double. valueOf() method. Let's see the simple code to convert int to Double in java.


2 Answers

Use this String.valueOf(value);

like image 112
URAndroid Avatar answered Oct 24 '22 05:10

URAndroid


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); 
like image 30
K_Anas Avatar answered Oct 24 '22 06:10

K_Anas