-11

How can I store a int value in a String?

For example:

int number = 10;
string word = number;

4 Answers4

0

You can use the static method:

String.valueOf(number)

Or

new Integer(number).toString();
0
int number = 10;
string word = Integer.toString(number);

this will convert the integer "number" to string to be able to store it inside a string without changing it's value just that easy, good luck :)

ELTA
  • 1,474
  • 2
  • 12
  • 25
0

There are multiple ways to convert an int to string.

String word = Integer.toString(number);

String word = String.valueOf(number);

String word = new Integer(number).toString();

String word = String.format ("%d", number);

etc..

There are more ways to do this. But I prefer the 1st one. Just do some googling you will find more answers! :)

Minudika
  • 851
  • 6
  • 23
0

Normal ways would be Integer.toString(number) or String.valueOf(number). But, You can try this:

int number = 10;
String str = String.valueOf(number);

Or

StringBuilder sb = new StringBuilder();
sb.append("");
sb.append(number);
String str = sb.toString();
P113305A009D8M
  • 344
  • 1
  • 4
  • 13