2

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?

3
  • 1
    Is there IntToString method in your class file - myclassname? Is the arguement types are matching? Commented Jun 11, 2012 at 13:45
  • 3
    String.valueof(number) Commented Jun 11, 2012 at 13:47
  • 1
    @kakemonsteret remember to mark an answer as correct as it motivates other users to help you in the future. Commented Jun 12, 2012 at 14:49

8 Answers 8

4

Try this.

int number = 1;
String numberstring = Integer.toString(number);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - both String.valueOf() and Integer.toString() worked.
3

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 + "";

Comments

2

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?

Comments

2

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 + "";

Comments

1

One way to do this with very little code would be like this:

int number = 1;
String numberstring = number + "";

Comments

1

Are you expecting this -

int numb = 1;
String val = String.valueOf(numb);

Comments

1
int number=1;
String S = String.valueOf(number);

try this code... works for me :)

Comments

1

In Java, int to String is simple as

String numberstring = String.valueOf(number);

This applies to Android too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.