Reputation:
This doesn't work:
int number = 1;
String numberstring = IntToString(number);
I get "The method IntToString(int) is undefined for the type (myclassname)"
I must be tired here. What the heck am I forgetting?
Upvotes: 2
Views: 7883
Reputation:
These ones are the ones that seems to work "out of the box", without importing any special classes:
String numberstring = String.valueOf(number);
String numberstring = Integer.toString(number);
String numberstring = number + "";
Upvotes: 2
Reputation: 89189
In Java, int to String is simple as
String numberstring = String.valueOf(number);
This applies to Android too.
Upvotes: 1
Reputation: 2595
int number=1;
String S = String.valueOf(number);
try this code... works for me :)
Upvotes: 1
Reputation: 321
You can do either:
String numberstring = number.toString();
or
String numberstring = Integer.toString(number)
or (as a tricky thing sometimes I do this)
String numberstring = 1 + "";
Upvotes: 3
Reputation: 24506
Are you expecting this -
int numb = 1;
String val = String.valueOf(numb);
Upvotes: 1
Reputation: 25164
Why not this :
int number = 1;
String numberstring = number+"";
Also make sure that :
Is there IntToString
method in your class file - myclassname
? Is the arguement types are matching?
Upvotes: 2
Reputation:
One way to do this with very little code would be like this:
int number = 1; String numberstring = number + "";
Upvotes: 1
Reputation: 1061
Try this.
int number = 1;
String numberstring = Integer.toString(number);
Upvotes: 4